我試圖使用兩個按鈕來動態添加和刪除線性佈局。如何通過按鈕單擊添加和刪除線性佈局
protected void createT() {
// -----------------------------------------------
count++;
LinearLayout temp_ll, frame;
frame = new LinearLayout(this);
frame.setOrientation(LinearLayout.VERTICAL);
frame.setId(count);
EditText temp1, temp2;
for (int i=0; i<numClass; i++) {
temp_ll = new LinearLayout(this);
temp_ll.setOrientation(LinearLayout.HORIZONTAL);
temp1 = new EditText(this);
temp2 = new EditText(this);
temp2.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
temp1.setHint("class name");
temp2.setHint("grade");
temp_ll.addView(temp1);
temp_ll.addView(temp2);
frame.addView(temp_ll);
}
ll.addView(frame);
}
protected void deleteT() {
// --------------------------------------
if (count > 0) {
LinearLayout temp = new LinearLyout(this);
temp = (LinearLayout) findViewById(count);
temp.removeAllViews();
temp.setVisibility(View.GONE);
count--;
}
}
- 我每次按添加按鈕,它會調用
createT()
- 每次我按下德爾按鈕,它會調用
deleteT()
的問題是,我使用計數變量來跟蹤linearLayout
ID。
第一次當我按加按鈕x次,然後按del按鈕一切都很好。
問題在於壓制後ADD第二次。
什麼是錯誤日誌? –
沒有錯誤,只是「del」按鈕在第一次沒有響應後 – Brian
想要刪除LinearLayout或任何特定的一個...形式向上或向下? –