Ответ 1
Почему вы написали linearLayout.getParent()
, вы должны сделать все это прямо на LinearLayout
if(((LinearLayout) linearLayout).getChildCount() > 0)
((LinearLayout) linearLayout).removeAllViews();
Я создаю linearlayout, который ссылается на элемент xml. Внутри этого linearlayout я динамически помещаю текстовое представление, так что не беря их из xml. Теперь мне нужно удалить эти текстовые изображения из линейного файла. Я пробовал это:
if(((LinearLayout) linearLayout.getParent()).getChildCount() > 0)
((LinearLayout) linearLayout.getParent()).removeAllViews();
но это не сработает. Как я могу сделать? Спасибо, Mattia
Почему вы написали linearLayout.getParent()
, вы должны сделать все это прямо на LinearLayout
if(((LinearLayout) linearLayout).getChildCount() > 0)
((LinearLayout) linearLayout).removeAllViews();
Привет, пожалуйста, попробуйте этот код для меня.
public class ShowText extends Activity {
/** Called when the activity is first created. */
LinearLayout linearLayout;
TextView textView,textView1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textView=new TextView(this);
textView1=new TextView(this);
textView.setText("First TextView");
textView1.setText("First TextView");
linearLayout=(LinearLayout) findViewById(R.id.mn);
linearLayout.addView(textView);
linearLayout.addView(textView1);
linearLayout.removeAllViews();
}
}