• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Table layout programatically

pecmcrl

Lurker
Hi.......i am new to android development.. Iam trying to create a table layout programatically in the activity it self without using xml file........ Please help to know can i do it.

Can anyone find the error in following code.....

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class Tablelayout extends Activity{
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);

LayoutParams params=new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);

TextView tv=new TextView(this);
tv.setLayoutParams(params);
tv.setTextColor(Color.RED);

TableRow tr=new TableRow(this);
tr.addView(tv);

TableLayout tl=new TableLayout(this);
TableLayout.LayoutParams layoutparams=new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
tl.addView(tr);

this.addContentView(tl, layoutparams);
}
}
 
Is the app crashing? Try to explain some more. If the app is crashing, look in logcat to see what exception is beeing thrown.
 
While running its showing error like "the application has stopped unpectedly. please try again" and the logcat showing runtime error message at dalvik.system.NativeStart.man(Native method)
 
Back
Top Bottom