1
我有一个ArrayList,它的层次结构有3个级别。类别,论坛,ChildForum。 但论坛和ChildForum,它们具有相同的属性(最重要的属性是nodeId和parentNodeId)。而一个coupe论坛里面没有任何ChildForum。过滤器添加ArrayList <object>到HashMap
Category------
|
Forum---------
| |
| ChildForum--------
| |
|______________________Thread
所以我想找到一种方法,结合他们进入列表视图,并onClickItem,检查出其论坛有孩子或不,这样我就可以浏览查看到正确的片段
这是我现在已经完成:
nodeList = new ArrayList<Node>(); //nodeList contains Category, Forum, and ChildForum
forumNodeList = new ArrayList<Node>();
childList = new ArrayList<Node>(); // temp array
forumChildNodeList = new HashMap<String, ArrayList<Node>>();
填充数据
for (int i = 0; i < nodeList.size(); i++) {
if (nodeList.get(i).getParent_node_id().equals(nodeId)) { //nodeId = categoryId
forumNodeList.add(nodeList.get(i));
}
for (int j = 0; j < forumNodeList.size(); j++) {
if (forumNodeList.get(j).getNodeId()
.equals(nodeList.get(i).getParent_node_id())) {
childList.add(nodeList.get(i));
// Log.d("childList", "" + childList.size());
forumChildNodeList.put(
forumNodeList.get(j).getNodeId(), childList);
}
forumChildNodeList.put(forumNodeList.get(j).getNodeId(),
childList);
}
}
setOnClickItem:
getListView().setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
if (forumChildNodeList.get(
forumNodeList.get(position).getNodeId()).size() > 0) {
//Fragment Transaction to ChildForumFragment
} else {
//Fragment Transaction to ThreadFragment
}
}
});
当我显示在onClick的日志。它看起来像所有的HashMap与论坛ID具有相同的ChildForum。实际上其中有些人没有任何childForum。 我知道肯定的,For-loops和if-conditions都有错误。或者我错过了什么?请帮忙! 在此先感谢!
问题是什么? –
对不起!我更新了错误! HashMap forumChildNodeList返回数据是错误的! – Max