【发布时间】:2012-07-24 11:23:35
【问题描述】:
我的 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;
【问题讨论】:
-
嘿里卡多!欢迎来到 SO。您想出了一个不错的应用程序创意。但是您必须采取措施并努力实施它。与我们分享一些您编写的代码或您在什么时候未能实现它。每个人都在这里为您提供帮助。
-
我猜你正在尝试重新实现 ExpandableListView。这是一个完全可自定义的元素,每次您告诉它时都会显示子列表。
-
我更新了我的问题。我需要的是添加一个layout1。当我单击按钮 plus2 时,我需要在 layout1 中插入一个 layout1。我需要这个多次和不同的 id 布局
-
您可以通过 布局并根据需要设置可见性来实现此目的。
-
我的问题是,当我在第一个 layout1 中单击按钮加 2 时,他在第二个 layout1 下方添加了 layout2。我的问题在于 id,因为我每次都添加相同的内容,但我不知道如何修复它。
标签: android button android-linearlayout layout-inflater