Add table row dynamically in Android?
I need to add table row by using 开发者_如何学GoJava code only (not XML design).
In that table row I have to add two textview fields. I use the code below.
TableRow tblrow=new TableRow(this);
tblrow.addView(Textview1);
tblrow.addView(Textview2);
But it only displays Textview1. How to view both?
I am new to Android.
TableRow tr1;
//TableRow tr2;
TextView txt9;
TableLayout tl = (TableLayout)findViewById(R.id.myTableLayout);
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
LinearLayout.LayoutParams layoutParams =
new LinearLayout.LayoutParams(width, LayoutParams.FILL_PARENT);
for (int i = 0; i < str_arr.length-1; i++)
{
string_arr = fun1.split(str_arr[i].trim(),"^");
tr1 = (TableRow) new TableRow(this);
txt9=new TextView(this);
txt9.setText(strinarr[0]);
txt9.setBackgroundColor(intblue);
txt9.setTextColor(intwhite);
tr1.addView(txt9);
tl.addView(tr1,new TableLayout.LayoutParams(layoutParams));
}
精彩评论