2
我想在android应用程序中创建一个简单的ExpandableListView。使用HashMap创建ExpandableListView的错误<String,List <String>>
这是准备用于循环的ExpandableListView.I数据的代码,因为在我的应用程序中,这些数据在运行时即将到来,所以我无法识别它将持续多久。
header = new ArrayList<String>();
child = new HashMap<String, List<String>>();
header.add("Top 250");
header.add("Now Showing");
header.add("Coming Soon");
for (int i = 0; i < 3; i++) {
List<String> Map = new ArrayList<String>();
Map.add("Hello:" + i);
child.put(header.get(i), Map);
}
并填充ExpandableListView我创建自定义适配器在这里是代码。
@Override
public Object getChild(int groupPosition, int childPosition) {
String headerData = this._listDataHeader.get(groupPosition);
List<String> listData = this._listDataChild.get(headerData);
return listData.get(childPosition);
}
,当我试图运行在ExpandableListView这个应用程序标题出现完美的,但是当我在特定的标题单击该应用程序失败。
这里是logcat。
java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
at java.util.ArrayList.get(ArrayList.java:304)
com.kamani.expandablelistdemo.MyCustomAdpater.getChild(MyCustomAdpater.java:36)
com.kamani.expandablelistdemo.MyCustomAdpater.getChildView(MyCustomAdpater.java:51)
android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:451)
我知道,我在getChild收到错误()返回中的数据的方法,它说IndexOutOfBoundsException异常,但无法了解如何使它正确,以便它在一个标题显示一个一个刺?