例如,如果我有一个班级:
class Folder {
public String name;
public ArrayList<Folder> subFolders;
public ArrayList<Folder> subFolders;
}
我正在尝试使用自定义ListView
填充ArrayAdapter
,然后浏览填充了数据的ArrayList
“文件夹”。我尝试这样的事情来展示subFolders
:
private OnItemClickListener listlistener = new OnItemClickListener() {
@Override
public void onItemClick(int position, long arg3) {
currentFolder = (Category) parent.getItemAtPosition(position);
folders = currentFolder.subFolders;
folderAdapter.notifyDataSetChanged();
}
};
但它不起作用。有什么建议可以帮助解决这个问题吗?
答案 0 :(得分:0)
在自定义ArrayAdapter中创建一个Public方法
public void setList(List<Item> items){
this.items = items;
}
现在
private OnItemClickListener listlistener = new OnItemClickListener() {
@Override
public void onItemClick(int position, long arg3) {
currentFolder = (Category) parent.getItemAtPosition(position);
folders = currentFolder.subFolders;
folderAdapter.setList(folders);
folderAdapter.notifyDataSetChanged();
}
};