how to add child to tablerow dynamically in android?
I am new to android. I have to add table row in a dynamic manner.In that row i need to add two child(Textview).But it displays only one textview only(first one). Here is my code
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TableRow;
import android.widget.TextView;
public class DynamicTextView extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ScrollView sv = new ScrollView(this);
    LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);
    sv.addView(ll);
    for(int i=0;i<30;i++){
     TableRow tbrow=new 开发者_如何学CTableRow(this);
     TextView tv1=new TextView(this);
     tv1.setText("Dynamic TextView");
     TextView tv2=new TextView(this);
     tv2.setText(" No : "+i);
     tbrow.addView(tv1);
     tbrow.addView(tv2);
     ll.addView(tbrow);
    }
    setContentView(sv);
  }
}
output is:
   Dynamic TextView
   Dynamic TextView
   Dynamic TextView
   Dynamic TextView
   .........
   ..........
I add tablelayout.After adding tablerow view to the tablelayout i got the expected output.
  ........
  .........
  TableLayout tblayout=new TableLayout(this);
  tblayout.addView(tbrow);
  ...........
  ..............
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论