I’m having trouble in my Android application. I need add LinearLayouts inside another linearlayout. I’m using inflation. I’m trying to explain better.
__________________________________________________
| |
| BUTTON PLUS 1 |
| __________________________________________ |
| | layout1 Button Plus 2 | |
| | ______________btnRemove1________ | |
| | | layout2 | | |
| | | | | |
| | |_____________btnRemove2________| | |
| |_________________________________________| |
| |
| __________________________________________ |
| | layout1 Button Plus 2 | |
| | ______________btnRemove1________ | |
| | | layout2 | | |
| | | | | |
| | |_____________btnRemove2________| | |
| |_________________________________________| |
| |
|__________________________________________________|
My objective is: When I click on button plus1 add the layout1. When I click in button plus2 add the layout 2 inside layout1. My problem is that I need this a multiple times and the layouts with different id’s.
When I click on btnRemove1 I need to remove the layout1 and layout2 simultaneously. When I click btnRemove2 I need to remove layout2.
Here is my code
//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;
On possible way is to set the Tag value on the layouts and the button as you add them. Place the layouts in a Map based on the tag. Then use the tag when the button is clicked to fetch the Layout from the map and remove it. The tag is an internal marker never shown on the UI.