我有一个可扩展列表视图,当有人单击组行时,它需要动态添加子行。最好的方法是向我的服务器发送一个 AsyncHttp 请求,然后服务器用我解析成的 json 和 Object 进行响应。这样做的问题是,如果 json 为空,我需要在 OnClickGroupListener 上返回 true,如果 json 有数据,则需要返回 false。我该怎么做呢?
更新** * ****
我将以下内容添加到我的代码中:
private boolean childrenLoaded;
public boolean onGroupClick(ExpandableListView expandableListView, View view, int i, long l) {
if(!childrenLoaded){
getChildren(i);
}else{
return false;
}
return true;
}
public void getChildren(int position){
//HttpAsync request here
onSuccess(json){
childrenLoaded = true;
if (json has data){
listview.performclick(arguments for perform click);
}else{
exit
}
}
}