我的 Android 应用程序有问题。我需要在另一个线性布局中添加线性布局。我正在使用通货膨胀。我试图更好地解释。
__________________________________________________
| |
| BUTTON PLUS 1 |
| __________________________________________ |
| | layout1 Button Plus 2 | |
| | ______________btnRemove1________ | |
| | | layout2 | | |
| | | | | |
| | |_____________btnRemove2________| | |
| |_________________________________________| |
| |
| __________________________________________ |
| | layout1 Button Plus 2 | |
| | ______________btnRemove1________ | |
| | | layout2 | | |
| | | | | |
| | |_____________btnRemove2________| | |
| |_________________________________________| |
| |
|__________________________________________________|
我的目标是:当我单击按钮 plus1 时,添加 layout1。当我单击按钮 plus2 时,在 layout1 中添加布局 2。我的问题是我需要这个多次和具有不同 id 的布局。
当我单击 btnRemove1 时,我需要同时删除 layout1 和 layout2。当我单击 btnRemove2 时,我需要删除 layout2。
这是我的代码
//Button plus 1
case R.id.se_ibAddAddressPostal:
LayoutInflater inflaterAddressPostal = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout addressPostal = (LinearLayout)inflaterAddressPostal.inflate(R.layout.socio_form_structured_postal, null);
LinearLayout lLayoutAddressPostal;
lLayoutAddressPostal = (LinearLayout)findViewById(R.id.se_contentAdressPostal);
lLayoutAddressPostal.addView(addressPostal);
break;
//Button plus 2
case R.id.sfsp_ivMoreAddressPostal:
ImageButton imbtMoreAddress = (ImageButton)findViewById(R.id.sfsp_ivMoreAddressPostal);
imbtMoreAddress.setVisibility(imbtMoreAddress.INVISIBLE);
LayoutInflater inflaterAddressPostal2 = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout addressPostal2 = (LinearLayout)inflaterAddressPostal2.inflate(R.layout.socio_form_structured_postal2,null);
LinearLayout lLayoutAddressPostal2;
lLayoutAddressPostal2 = (LinearLayout)findViewById(R.id.se_contentAdressPostal);
lLayoutAddressPostal2.addView(addressPostal2);
break;