在可扩展列表视图中动态添加子视图项

时间:2014-05-21 11:21:25

标签: android expandablelistview

在我的Android应用程序中,我需要根据按钮点击动态添加子视图。我不知道该怎么做。我分享样本图像。如果有人知道请帮助我 enter image description here

2 个答案:

答案 0 :(得分:1)

我找到了我的问题的答案。对于每个按钮单击只是膨胀xml desiged布局。所以布局可以逐个添加。代码在这里

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--;
    }

答案 1 :(得分:0)

在您的Activity中实现OnChildClickListener并实现此方法..

@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;
}

这对你有用吗?

相关问题