Android 如何在expandableListview中将子级动态添加到特定组中? alertDialogBuilder.setPositiveButton(“确定”,新的DialogInterface.OnClickListener(){ @凌驾 公共空间点击( 对话框接口对话框, int(其中){ 试一试{ 费用=editText.getText().toString(); inta=(int)getGroupId(groupPosition); Log.e(“组id”,String.valueOf(a)); 对象准备列表数据(费用,(int)getGroupId(groupPosition)); }捕获(例外e){ Log.e(“123”,e.toString()); } } }); public void prepareListData(字符串s,int位置){ 列表费用=新的ArrayList(); 费用。添加(s); listDataChild.put(listDataHeader.get(position),expenses); listAdapter=新的ExpandableListAdapter(此,listDataHeader,listDataChild); }
在这里,我想将不同的费用添加到不同的组(标题),但费用会覆盖到标题中的前一个Android 如何在expandableListview中将子级动态添加到特定组中? alertDialogBuilder.setPositiveButton(“确定”,新的DialogInterface.OnClickListener(){ @凌驾 公共空间点击( 对话框接口对话框, int(其中){ 试一试{ 费用=editText.getText().toString(); inta=(int)getGroupId(groupPosition); Log.e(“组id”,String.valueOf(a)); 对象准备列表数据(费用,(int)getGroupId(groupPosition)); }捕获(例外e){ Log.e(“123”,e.toString()); } } }); public void prepareListData(字符串s,int位置){ 列表费用=新的ArrayList(); 费用。添加(s); listDataChild.put(listDataHeader.get(position),expenses); listAdapter=新的ExpandableListAdapter(此,listDataHeader,listDataChild); },android,expandablelistadapter,Android,Expandablelistadapter,在这里,我想将不同的费用添加到不同的组(标题),但费用会覆盖到标题中的前一个 如何将不同的多个值添加到不同的组(标题)?请指导我。您不应该每次更改数据时都实例化ExpandableListAdapter 您应该只修改数据列表,然后调用listAdapter: alertDialogBuilder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override
如何将不同的多个值添加到不同的组(标题)?请指导我。您不应该每次更改数据时都实例化ExpandableListAdapter 您应该只修改数据列表,然后调用listAdapter:
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);
}
这将自动应用数据更改 欢迎,你可以勾选我的答案;-)
adapter.notifyDataSetChanged();