2013-02-25 81 views
0

例如,如果我有一個類:填充的ListView與ArrayAdapter和導航

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

在您的自定義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(); 

    } 
}; 
+0

當我這樣做的'listView' – pepela 2013-02-25 13:31:53

+0

這樣的老物件留了如何使用'getView處理()'方法來顯示新的數據? – pepela 2013-02-25 13:52:16