0

I need to add table row by using Java 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.

0

1 Answer 1

2
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));
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.