You should create TextView Dynamically and add in ll...
for(int i=1 ; i<= 5 ; i++){
TextView tv1 = new TextView(getApplicationContext());
tv1.setText("SomeTextGoesHere");
ll.addView(tv1);
}
Pregunta
Here the code sample:
TableLayout ll = (TableLayout)findViewById(R.id.dyn_lyr);
also same with LinearLayout
//LinearLayout ll = (LinearLayout)findViewById(R.id.dyn_lyr);
TextView tv1 = (TextView) findViewById(R.id.testEditText);
tv1.setText("SomeTextGoesHere");
for(int i=1 ; i<= 5 ; i++){
ll.addView(tv1);
}
the LinearLayout/Table is inside ScrollView!
Solución
You should create TextView Dynamically and add in ll...
for(int i=1 ; i<= 5 ; i++){
TextView tv1 = new TextView(getApplicationContext());
tv1.setText("SomeTextGoesHere");
ll.addView(tv1);
}
Otros consejos
There is not enought info but I guess that Tv1 already has a parent . I guess that you should add new TextView every time . Try this one. Ok then create brand new TextView
for(int i=1 ; i<= 5 ; i++){
TextView tv1 = new TextView(this);
tv1.setText("SomeTextGoesHere");
ll.addView(tv1);
}
If you are using findViewById
, the resulting view is already a part of your layout and has a parent. Each view can only be added to a ViewGroup once. You need to be making new TextViews and adding those to your LinearLayout. You can do this either via the TextView constructor or a LayoutInflater with a separate xml layout.