1

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 enter image description here

user1517638
  • 972
  • 1
  • 10
  • 16

2 Answers2

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