我是Android的新手。任何人都可以爲我的問題提供一些想法。如何從Android的佈局中刪除子佈局?
/* Parent Linear Layout */
final LinearLayout par_layout=new LinearLayout(this);
par_layout.setOrientation(LinearLayout.VERTICAL);
/* Child Linear Layout */
final LinearLayout chl_layout=new LinearLayout(this);
chl_layout.setOrientation(LinearLayout.VERTICAL);
TextView tv_name=new TextView(this);
tv_name.setText("Name ");
TextView tv_item=new TextView(this);
tv_item.setText("Items ");
Button btn_submit=new Button(this);
btn_submit.setText("Submit");
btn_submit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
par_layout.removeAllViewsInLayout();
}
});
chl_layout.addView(tv_name);
chl_layout.addView(tv_item);
chl_layout.addView(btn_submit);
par_layout.addView(chl_layout);
setContentView(par_layout);
在按鈕點擊時上面的代碼中,我希望清除par_layout中的chl_layout。但是我不能。任何人都可以提出一些想法
注: 下面的代碼也不能正常工作下面的代碼
par_layout.removeView(chl_layout);
我已經使用這個,但它不會刪除chl_layout – Alex 2010-10-27 06:21:00
@Alex - 那麼爲什麼你接受這個? – katzenhut 2014-04-09 08:34:42