In my android app, i need to dynamically add child view based on button click. i don't know how to do that. i share the sample image. if any one knows please help me
Asked
Active
Viewed 4,943 times
1

user1517638
- 972
- 1
- 10
- 16
-
my question and the above link both r different – user1517638 May 21 '14 at 11:31
-
simply create your views in xml, then onclick button setvisibility or gone – Engr Waseem Arain May 21 '14 at 11:33
-
Your question is so vague that we can assume it is a duplicate. If it is not : provide more details on what/why it is different and the duplicate will be removed. – ben75 May 21 '14 at 11:34
-
engar Waseem Arain, the child view may be 10 or 1000 based on user. so it is not possible in xml layout – user1517638 May 21 '14 at 11:40
-
@user1517638 10 or 1000 based on user?? – Engr Waseem Arain May 21 '14 at 12:02
2 Answers
1
i found the answer for my question. for every button click just inflate the xml desiged layout. so the layout can be added one by one. the codes are here
LayoutInflater IInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
String[] names = { "Joe", "Jane", "Herkimer" };
while (run >= 1) {
View storeitems = IInflater.inflate(R.layout.product_child_item,
null);
productCode = (TextView) storeitems.findViewById(R.id.productCode);
productName = (TextView) storeitems.findViewById(R.id.productName);
noOfQuantity = (TextView) storeitems
.findViewById(R.id.noOfQuantity);
int i = run - 1;
productCode.setText(names[i]);
linearLayout.addView(storeitems, 0);
run--;
}

user1517638
- 972
- 1
- 10
- 16
0
Implement OnChildClickListener in your Activity and implemet this method..
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
//Add new chid data in your list (ex ArrayLis or Array whatever you use)
adapter.notifyDataSetChanged() // BaseExpandableListAdapter's adapter...
return true;
}
Is it work work for you?

chiragkyada
- 3,585
- 3
- 17
- 18