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);
}
}
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);
}
}