Hy大家。
我的Android应用程序遇到了麻烦。我需要在另一个linearlayout中添加LinearLayouts。我正在使用通货膨胀。我想更好地解释一下。
__________________________________________________
| |
| BUTTON PLUS 1 |
| __________________________________________ |
| | layout1 Button Plus 2 | |
| | ______________btnRemove1________ | |
| | | layout2 | | |
| | | | | |
| | |_____________btnRemove2________| | |
| |_________________________________________| |
| |
| __________________________________________ |
| | layout1 Button Plus 2 | |
| | ______________btnRemove1________ | |
| | | layout2 | | |
| | | | | |
| | |_____________btnRemove2________| | |
| |_________________________________________| |
| |
|__________________________________________________|
我的目标是:当我点击按钮加1时添加layout1。当我点击按钮加2时,在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;
答案 0 :(得分:0)
可能的方法是在添加布局和按钮时设置标记值。根据标记将布局放置在Map中。然后在单击按钮时使用标记从地图中获取布局并将其删除。标签是UI上从未显示的内部标记。
答案 1 :(得分:0)
您要找的是ExpandableListView。无需重新发明轮子。