![](/img/trans.png)
[英]Recyclerview onBindViewHolder called for all items when inside LinearLayout with weights
[英]Remove all items inside linearlayout
我创建了一个引用 xml 项目的线性布局。 在这个线性布局中,我动态地放置了一些文本视图,因此无需从 xml 中取出它们。 现在我需要从线性布局中删除这些文本视图。 我试过这个:
if(((LinearLayout) linearLayout.getParent()).getChildCount() > 0)
((LinearLayout) linearLayout.getParent()).removeAllViews();
但它不起作用。 我能怎么做? 谢谢,马蒂亚
你为什么写linearLayout.getParent()
?
您应该直接在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();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.