문제

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!

도움이 되었습니까?

해결책

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);
}

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top