n.setExpand(!n.isExpand()); 但是我们虽然改变了n 的状态,但是我们的n 并没有在赋值回去,这个时候我们的mAllNodes数据会发生变化么??
public abstract class TreeListViewAdapter<T> extends BaseAdapter
{
protected Context mContext;
protected List<Node> mAllNodes;
protected List<Node> mVisibleNodes;
protected LayoutInflater mInflater;
protected ListView mTree;
mTree.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id)
{
expandOrCollapse(position);
if (mListener != null)
{
mListener.onClick(mVisibleNodes.get(position), position);
}
}
});
}
/**
* 点击搜索或者展开
*
* @param position
*/
private void expandOrCollapse(int position)
{
Node n = mVisibleNodes.get(position);
if (n != null)
{
if (n.isLeaf())
return;
n.setExpand(!n.isExpand());
// 但是我们虽然改变了n 的状态,但是我们的n 并没有在赋值回去,这个时候我们的mAllNodes数据会发生变化么??
mVisibleNodes = TreeHelper.filterVisibleNodes(mAllNodes);
notifyDataSetChanged();
}
}