Double child added on expandable listview

Shr*_*uti 3 android duplicates expandablelistview expandablelistadapter

I have problem adding children ,when i add one child then on ui two child appear with same childposition..my problem is similar to these mentioned in following questions

Child Layout is repeating many times in ExpandableListView

/sf/ask/765713441/

但无法找到解决方案..请在此处查看我的代码

使用此双维数组给出了儿童的价值.

String[][] child = {
         mContext.getResources().getStringArray(R.array.alerts),
         mContext.getResources().getStringArray(R.array.alerts),
         mContext.getResources().getStringArray(R.array.alerts),
         mContext.getResources().getStringArray(R.array.alerts),
         mContext.getResources().getStringArray(R.array.alerts) };
Run Code Online (Sandbox Code Playgroud)

我用过这个:

@Override
  public int getChildrenCount(int groupPosition) {
    return child.length;
  }
Run Code Online (Sandbox Code Playgroud)

但是对于这个,孩子的数量是5,它显示了10个项目..

Lal*_*ani 6

看来你是硬编码的孩子位置,

  @Override
  public int getChildrenCount(int groupPosition) {
    return 1;
  }
Run Code Online (Sandbox Code Playgroud)

它应该在哪里 your_data_collection_size

另外,你有像硬编码的childId,

  @Override
  public long getChildId(int groupPosition, int childPosition) {
    return 0;
  }
Run Code Online (Sandbox Code Playgroud)

这应该是childPosition0

如果您还有任何疑问/问题,可以下载并查看我的问题demo example from you github,如果您有任何疑问,可以回复我.


小智 6

我有完全相同的问题,结果是因为我在OnGroupClickListener中的onGroupClick方法中返回false.这是一个解决方案:

@Override
public boolean onGroupClick(ExpandableListView parent, View v, int position, long id) {
    // ... do stuff //
    return true; // make sure you return true.
}
Run Code Online (Sandbox Code Playgroud)