0

例如,如果我有一堂课:

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();
    }
};

但它不起作用。有什么建议可以帮助解决这个问题吗?

4

1 回答 1

0

在您的自定义 ArrayAdapter 创建一个公共方法

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();

    }
};
于 2013-02-25T08:47:07.857 回答