Android expandableListView中getChildView()处的IndexOutofBoundException
我正在添加三个子对象,其名称为“所有住宅”“所有地块”和“所有商业”,我在运行时添加这三个对象,其父对象为“住宅”“地块”和“商业”,因此,换句话说,我在我的父对象中添加了三个其他类别作为子对象。我在加载expandableListview时会加载子对象数组的索引为0,但每当我尝试单击这些新创建的对象时,就会在方法getChildView()处出现indexoutofboundexception错误由于IndexOutOfBoundException invalid index 7 size为7,当我单击填充子数据时,调试器显示此错误,当我返回时,调试器在此方法中显示此IndexOutOfBoundException错误。 我修改的代码是Android expandableListView中getChildView()处的IndexOutofBoundException,android,indexing,arraylist,expandablelistview,indexoutofboundsexception,Android,Indexing,Arraylist,Expandablelistview,Indexoutofboundsexception,我正在添加三个子对象,其名称为“所有住宅”“所有地块”和“所有商业”,我在运行时添加这三个对象,其父对象为“住宅”“地块”和“商业”,因此,换句话说,我在我的父对象中添加了三个其他类别作为子对象。我在加载expandableListview时会加载子对象数组的索引为0,但每当我尝试单击这些新创建的对象时,就会在方法getChildView()处出现indexoutofboundexception错误由于IndexOutOfBoundException invalid index 7 size为7
private void displayListListView(){
final ExpandableListView listview = (ExpandableListView)mView. findViewById(R.id.expandableListView);
final ExpendableAdapter expendableAdapter = new ExpendableAdapter();
//ArrayList<PropertyParent> childs = new ArrayList<PropertyParent>();
//PropertyParent parent = new PropertyTypeInfo().new PropertyParent();
PropertyTypeInfo property = new PropertyTypeInfo();
for(int i=0;i<Utils.propertyTypesList.size();i++)
{
// if( Utils.propertyTypesList.size()>0)
//{
property = Utils.propertyTypesList.get(i);
//if(property.getParentId()=="1" && property!=null){
if(parent==null)
{
parent = new PropertyTypeInfo().new PropertyParent();
parent.setTypeId("9,8,21,22,20,24,25");
parent.setTitle(value.concat(property.getTitle()));
parent.setTitleAlt2("All Houses");
parent.setParentId("1");
parent.setTitleAlt1("All House");
childs= property.getChilds();
childs.add(0, parent);
}
//}
else if(parent.getTypeId()=="9,8,21,22,20,24,25"){
parent = new PropertyTypeInfo().new PropertyParent();
parent.setTypeId("12,23,11,19,26,27");
parent.setTitle(value.concat(property.getTitle()));
parent.setTitleAlt2("All Plots");
parent.setParentId("2");
parent.setTitleAlt1("Residential Plot");
childs= property.getChilds();
childs.add(0, parent);
}
else if(parent.getTypeId()== "12,23,11,19,26,27")
{
parent = new PropertyTypeInfo().new PropertyParent();
parent.setTypeId("13,15,17,14,16,18");
parent.setTitle(value.concat(property.getTitle()));
parent.setTitleAlt2("All Commercial");
parent.setParentId("3");
parent.setTitleAlt1("Commercial");
childs= property.getChilds();
childs.add(0,parent);
}
//else
//{
//}
}
// }
expendableAdapter.notifyDataSetChanged();
listview.setAdapter(expendableAdapter);
//expendableAdapter.notifyDataSetChanged();
listview.setOnChildClickListener(new OnChildClickListener() {
我的Json数据是
"meta": {
"status": "200",
"mesaage": "Data Successfully Retrieved"
},
"response": {
"type": [
{
"type_id": "1",
"title": "Homes",
"title_alt2": "Homes",
"parent_id": "",
"title_alt1": "Home",
"child_list": "9,8,21,22,20,24,25",
"childs": [
{
"type_id": "9,8,21,22,20,24,25",
"title": "All Homes",
"title_alt2": "All Houses",
"parent_id": "1",
"title_alt1": "All House"
},
{
"type_id": "9",
"title": "Houses",
"title_alt2": "Houses",
"parent_id": "1",
"title_alt1": "House"
},
{
"type_id": "8",
"title": "Flats",
"title_alt2": "Flats & Apartments",
"parent_id": "1",
"title_alt1": "Flat"
},
{
"type_id": "21",
"title": "Upper Portions",
"title_alt2": "Upper Portions",
"parent_id": "1",
"title_alt1": "Upper Portion"
},
{
"type_id": "22",
"title": "Lower Portions",
"title_alt2": "Lower Portions",
"parent_id": "1",
"title_alt1": "Lower Portion"
},
{
"type_id": "20",
"title": "Farm Houses",
"title_alt2": "Farm Houses",
"parent_id": "1",
"title_alt1": "Farm House"
},
{
"type_id": "24",
"title": "Rooms",
"title_alt2": "Rooms",
"parent_id": "1",
"title_alt1": "Room"
},
{
"type_id": "25",
"title": "Penthouse",
"title_alt2": "Penthouse",
"parent_id": "1",
"title_alt1": "Penthouse"
}
]
},
{
"type_id": "2",
"title": "Plots",
"title_alt2": "Plots",
"parent_id": "",
"title_alt1": "Plot",
"child_list": "12,23,11,19,26,27",
"childs": [
{
"type_id": "12,23,11,19,26,27",
"title": "All Plots",
"title_alt2": "All Plots",
"parent_id": "2",
"title_alt1": "Residential Plot"
},
{
"type_id": "12",
"title": "Residential Plots",
"title_alt2": "Plots",
"parent_id": "2",
"title_alt1": "Residential Plot"
},
{
"type_id": "23",
"title": "Plot Files",
"title_alt2": "Plots",
"parent_id": "2",
"title_alt1": "Plot File"
},
{
"type_id": "11",
"title": "Commercial Plots",
"title_alt2": "Commercial Plots",
"parent_id": "2",
"title_alt1": "Commercial Plot"
},
{
"type_id": "19",
"title": "Agricultural Land",
"title_alt2": "Agricultural Land",
"parent_id": "2",
"title_alt1": "Agricultural Land"
},
{
"type_id": "26",
"title": "Plot Forms",
"title_alt2": "Plot Forms",
"parent_id": "2",
"title_alt1": "Plot Form"
},
{
"type_id": "27",
"title": "Industrial Land",
"title_alt2": "Industrial Land",
"parent_id": "2",
"title_alt1": "Industrial Land"
}
]
},
{
"type_id": "3",
"title": "Commercial",
"title_alt2": "Commercial",
"parent_id": "",
"title_alt1": "Commercial Property",
"child_list": "13,15,17,14,16,18",
"childs": [
{
"type_id": "13",
"title": "Offices",
"title_alt2": "Offices",
"parent_id": "3",
"title_alt1": "Office"
},
{
"type_id": "15",
"title": "Shops",
"title_alt2": "Shops",
"parent_id": "3",
"title_alt1": "Shop"
},
{
"type_id": "17",
"title": "Warehouses",
"title_alt2": "Warehouses",
"parent_id": "3",
"title_alt1": "Warehouse"
},
{
"type_id": "14",
"title": "Factories",
"title_alt2": "Factories",
"parent_id": "3",
"title_alt1": "Factory"
},
{
"type_id": "16",
"title": "Buildings",
"title_alt2": "Buildings",
"parent_id": "3",
"title_alt1": "Building"
},
{
"type_id": "18",
"title": "Other",
"title_alt2": "Other",
"parent_id": "3",
"title_alt1": "Other"
}
]
}
]
}
}
请更改您的循环大小 你必须像这样循环条件 对于(int i=0;i
大小-1旁注:parent.getTypeId()=“9,8,21,22,20,24,25”。将==替换为.equals。还有,你为什么要把父母添加到你的孩子列表中?@carnal我工作的地方他们已经在根据网络服务从url获取数据,但现在他们想硬编码这三个类别——所有家庭,所有地块,所有商业化,因此,在所有家庭中,所有家庭的孩子来了,在所有绘图中,孩子来了,在将来,如果他们想添加另一个功能,他们可以硬编码以获得结果,而不改变API。同样是java.lang.IndexOutOfBoundsException:索引7无效,片段大小为7。类型$ExpandableAdapter.getChildView(Types.java:254)如果我将其设为Utils.propertyTypesList.size()-1则数组将无法正常遍历,就像它将遍历0和1索引一样,并将离开2索引,因此仅显示所有家庭所有绘图,但错误仍然存在,即在单击单选按钮填充数据后,i come bak indexoofbound异常错误出现,应用程序崩溃
"meta": {
"status": "200",
"mesaage": "Data Successfully Retrieved"
},
"response": {
"type": [
{
"type_id": "1",
"title": "Homes",
"title_alt2": "Homes",
"parent_id": "",
"title_alt1": "Home",
"child_list": "9,8,21,22,20,24,25",
"childs": [
{
"type_id": "9,8,21,22,20,24,25",
"title": "All Homes",
"title_alt2": "All Houses",
"parent_id": "1",
"title_alt1": "All House"
},
{
"type_id": "9",
"title": "Houses",
"title_alt2": "Houses",
"parent_id": "1",
"title_alt1": "House"
},
{
"type_id": "8",
"title": "Flats",
"title_alt2": "Flats & Apartments",
"parent_id": "1",
"title_alt1": "Flat"
},
{
"type_id": "21",
"title": "Upper Portions",
"title_alt2": "Upper Portions",
"parent_id": "1",
"title_alt1": "Upper Portion"
},
{
"type_id": "22",
"title": "Lower Portions",
"title_alt2": "Lower Portions",
"parent_id": "1",
"title_alt1": "Lower Portion"
},
{
"type_id": "20",
"title": "Farm Houses",
"title_alt2": "Farm Houses",
"parent_id": "1",
"title_alt1": "Farm House"
},
{
"type_id": "24",
"title": "Rooms",
"title_alt2": "Rooms",
"parent_id": "1",
"title_alt1": "Room"
},
{
"type_id": "25",
"title": "Penthouse",
"title_alt2": "Penthouse",
"parent_id": "1",
"title_alt1": "Penthouse"
}
]
},
{
"type_id": "2",
"title": "Plots",
"title_alt2": "Plots",
"parent_id": "",
"title_alt1": "Plot",
"child_list": "12,23,11,19,26,27",
"childs": [
{
"type_id": "12,23,11,19,26,27",
"title": "All Plots",
"title_alt2": "All Plots",
"parent_id": "2",
"title_alt1": "Residential Plot"
},
{
"type_id": "12",
"title": "Residential Plots",
"title_alt2": "Plots",
"parent_id": "2",
"title_alt1": "Residential Plot"
},
{
"type_id": "23",
"title": "Plot Files",
"title_alt2": "Plots",
"parent_id": "2",
"title_alt1": "Plot File"
},
{
"type_id": "11",
"title": "Commercial Plots",
"title_alt2": "Commercial Plots",
"parent_id": "2",
"title_alt1": "Commercial Plot"
},
{
"type_id": "19",
"title": "Agricultural Land",
"title_alt2": "Agricultural Land",
"parent_id": "2",
"title_alt1": "Agricultural Land"
},
{
"type_id": "26",
"title": "Plot Forms",
"title_alt2": "Plot Forms",
"parent_id": "2",
"title_alt1": "Plot Form"
},
{
"type_id": "27",
"title": "Industrial Land",
"title_alt2": "Industrial Land",
"parent_id": "2",
"title_alt1": "Industrial Land"
}
]
},
{
"type_id": "3",
"title": "Commercial",
"title_alt2": "Commercial",
"parent_id": "",
"title_alt1": "Commercial Property",
"child_list": "13,15,17,14,16,18",
"childs": [
{
"type_id": "13",
"title": "Offices",
"title_alt2": "Offices",
"parent_id": "3",
"title_alt1": "Office"
},
{
"type_id": "15",
"title": "Shops",
"title_alt2": "Shops",
"parent_id": "3",
"title_alt1": "Shop"
},
{
"type_id": "17",
"title": "Warehouses",
"title_alt2": "Warehouses",
"parent_id": "3",
"title_alt1": "Warehouse"
},
{
"type_id": "14",
"title": "Factories",
"title_alt2": "Factories",
"parent_id": "3",
"title_alt1": "Factory"
},
{
"type_id": "16",
"title": "Buildings",
"title_alt2": "Buildings",
"parent_id": "3",
"title_alt1": "Building"
},
{
"type_id": "18",
"title": "Other",
"title_alt2": "Other",
"parent_id": "3",
"title_alt1": "Other"
}
]
}
]
}
}