如何将 child 动态添加到 expandableListview 中的特定组?

How to add child dynamically into particular group in expandableListview?

alertDialogBuilder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(
                                DialogInterface dialog,
                                int which) {

                            try {
                               expenses = editText.getText().toString();

                                int a = (int)getGroupId(groupPosition);
                                Log.e("group id",String.valueOf(a));

                               obj.prepareListData(expenses,(int) getGroupId(groupPosition));

                            } catch (Exception e) {
                                Log.e("123", e.toString());
                            }

                        }
                    });

public void prepareListData(String s, int position) {

   List<String>  expenses = new ArrayList<String>();

    expenses.add(s);

    listDataChild.put(listDataHeader.get(position), expenses);
    listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);

}

在这里,我想将不同的费用添加到不同的组中(header),但是费用会覆盖之前的费用到 header。

如何将不同的多个值添加到不同的组中 (header)?请指导我。

您不应该在每次更改数据时都实例化 ExpandableListAdapter。

您应该只修改您的数据列表,然后调用 listAdapter:

adapter.notifyDataSetChanged();

这将自动应用数据更改!