[英]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.