Android - Adding Layout At Runtime To Main Layout
I am trying to add a tableLayout at runtime to the existing LinearLayout in main.xml. I have added a editText(R.id.editText1) in the main.xml. Here's my code. Its not working. I ge
Solution 1:
Before your loop add :
Arraylist<TableRow> tr = new ArrayList<TableRow>;
In the loop instead of :
TableRowtr=newTableRow(this);
Put :
tr.add(new TableRow(this));
And finally replace your tr
by tr.get(r)
. Something like these modifications should help you because, you erase your tr at each turn of your loop with your :
TableRowtr=newTableRow(this);
Solution 2:
Mr. Happy Go Lucky just do one thing write setContentView(R.layout.your Main Layout);
beofre text = (EditText)findViewById(R.id.editText1);
means at top of the onCreate()
method because we cant define any view
before setContentView.
without any setContentView
you cant find any view like as findViewById(R.id.editText1);
Solution 3:
Below line will be the first one after super.onCreate(savedInstanceState);
setContentView(mainLayout);
then only findViewByid
works
Post a Comment for "Android - Adding Layout At Runtime To Main Layout"