带和不带子android的ExpandableListview
我正在使用来自的NavingationalDrawer 以及从中使用ExpandableLisview 我将NavingationalDrawer定制为可扩展的listview “我的可展开列表视图”包含有子项和无子项的列表项 单击带有子项的项时,它会按预期展开,但由于For循环,这些项会重复 当单击没有子项的项目时,它会崩溃,这是出乎意料的带和不带子android的ExpandableListview,android,android-asynctask,expandablelistview,Android,Android Asynctask,Expandablelistview,我正在使用来自的NavingationalDrawer 以及从中使用ExpandableLisview 我将NavingationalDrawer定制为可扩展的listview “我的可展开列表视图”包含有子项和无子项的列表项 单击带有子项的项时,它会按预期展开,但由于For循环,这些项会重复 当单击没有子项的项目时,它会崩溃,这是出乎意料的 private class GetCatList extends AsyncTask<String, Void, Void> {
private class GetCatList extends AsyncTask<String, Void, Void> {
@Override
protected void onPreExecute() {
//expListView.setVisibility(8);
super.onPreExecute();
}
@Override
protected Void doInBackground(String... params) {
if (NetworkCheck.isNetworkAvailable(getApplicationContext()) == true) {
//navDrawerItems = new ArrayList<NavDrawerItem>();
// Creating service handler class instance
ServiceHandler sh = new ServiceHandler();
// Making a request to url and getting response
String jsonStr = sh.makeServiceCall(All_link.CATEGORY_URL,
ServiceHandler.GET);
Log.d("Response: ", "> " + jsonStr);
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
// Getting JSON Array node
cat = jsonObj.getJSONArray(All_link.TAG_NEWS);
String err = jsonObj.getString(All_link.TAG_ERROR);
Log.e("------>Error", String.valueOf(err));
if (err.equals("1")) {
} else {
// looping through All Contacts
for (int i = 0; i < cat.length(); i++) {
JSONObject c = cat.getJSONObject(i);
String id = c.getString(All_link.TAG_CAT_ID);
String cat_name = c
.getString(All_link.TAG_CAT_NAME);
String image_icon = c.getString("image_icon");
/*navDrawerItems.add(new NavDrawerItem(cat_name,
image_icon, navMenuIcons.getResourceId(
1, -1), true
,"1",id));*/
listDataHeader.add("News Category");
list_items.add(cat_name);
listDataChild.put(listDataHeader.get(i), list_items);
Log.e("list_items", "karlist "+list_items);
}
listDataHeader.add("News Today");
}
} catch (JSONException e) {
e.printStackTrace();
}
} else {
Log.e("ServiceHandler",
"Couldn't get any data from the url");
}
} else {
Log.e("Network Error", "Internet Connection Error");
error_flag = 1;
// error = "Internet Connection Error";
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
if (error_flag == 1) {
expListView.setVisibility(8);
// main_error.setText("Internet Connection Error! Please check your network settings and try again");
// main_error.setVisibility(0);
} else {
/*
* navDrawerItems.add(new NavDrawerItem(navMenuTitles[1],
* navMenuIcons .getResourceId(0, -1),"1"));
*/
expListView.setVisibility(0);
// main_error.setText("");
// main_error.setVisibility(8);
// Recycle the typed array
navMenuIcons.recycle();
expListView
.setOnItemClickListener(new SlideMenuClickListener());
// setting the nav drawer list adapter
/*adapter = new NavDrawerListAdapter(getApplicationContext(),
navDrawerItems);*/
listAdapter=new ExpandableListAdapter(MainActivity.this, listDataHeader, listDataChild);
expListView.setAdapter(listAdapter);
expListView.setItemChecked(0, true);
expListView.setSelection(0);
}
}
}
私有类GetCatList扩展了异步任务{
@凌驾
受保护的void onPreExecute(){
//expListView.setVisibility(8);
super.onPreExecute();
}
@凌驾
受保护的Void doInBackground(字符串…参数){
if(NetworkCheck.isNetworkAvailable(getApplicationContext())==true){
//navDrawerItems=新的ArrayList();
//创建服务处理程序类实例
ServiceHandler sh=新的ServiceHandler();
//向url发出请求并获得响应
字符串jsonStr=sh.makeServiceCall(所有链接.CATEGORY\uURL,
ServiceHandler.GET);
Log.d(“响应:”、“>”+jsonStr);
if(jsonStr!=null){
试一试{
JSONObject jsonObj=新的JSONObject(jsonStr);
//获取JSON数组节点
cat=jsonObj.getJSONArray(All_link.TAG_NEWS);
String err=jsonObj.getString(All_link.TAG_ERROR);
Log.e(“---->Error”,String.valueOf(err));
如果(误差等于(“1”)){
}否则{
//通过所有触点循环
对于(int i=0;i
只有一条备注:listDataHeader.add(“新闻类别”)代码>。这样做cat.length()
次。所以你会经常看到那群人。请解释一下<代码>列出项目
。请显示类型和定义。感谢回复。。。我解决了我的问题。。借助