2013-04-18 61 views
0

我正在開發一個可擴展的ListView多達10層。如何將窗口小部件Expandable ListView展開爲10層?

我正在使用下面的代碼到第二層只能前進。

我用下面的代碼:

public void onCreate(Bundle savedInstanceState) { 
    try{ 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

    SimpleExpandableListAdapter expListAdapter = 
     new SimpleExpandableListAdapter(
       this, 
       createGroupList(),    // Creating group List. 
       R.layout.group_row,    // Group item layout XML.   
       new String[] { "Group Item" ,"level"}, // the key of group item. 
       new int[] { R.id.row_name ,R.id.row_name2}, // ID of each group item.-Data under the key goes into this TextView.     
       createChildList(),    // childData describes second-level entries. 
       R.layout.child_row,    // Layout for sub-level entries(second level). 
       new String[] {"Sub Item","level"},  // Keys in childData maps to display. 
       new int[] { R.id.grp_child,R.id.grp_child2}  // Data under the keys above go into these TextViews. 
      ); 

     setListAdapter(expListAdapter);  // setting the adapter in the list. 

    }catch(Exception e){ 
     System.out.println("Errrr +++ " + e.getMessage()); 
    } 

} 

/* Creating the Hashmap for the row */ 
@SuppressWarnings("unchecked") 
private List createGroupList() { 
     ArrayList result = new ArrayList(); 
     for(int i = 0 ; i < 15 ; ++i) { // 15 groups........ 
     HashMap m = new HashMap(); 
     m.put("Group Item","شماره گروه " + i); // the key and it's value. 
     m.put("level","لایه اول "); 

     result.add(m); 
     } 
     return (List)result; 
} 

/* creatin the HashMap for the children */ 
@SuppressWarnings("unchecked") 
private List createChildList() { 

    ArrayList result = new ArrayList(); 
    for(int i = 0 ; i < 15 ; ++i) { // this -15 is the number of groups(Here it's fifteen) 
     /* each group need each HashMap-Here for each group we have 3 subgroups */ 
     ArrayList secList = new ArrayList(); 
     for(int n = 0 ; n < 3 ; n++) { 
     HashMap child = new HashMap();   
     child.put("Sub Item", "شماره زیر گروه " + n); 
     child.put("level", "لایه دوم "); 
     secList.add(child); 
     } 
    result.add(secList); 
    }   
    return result; 
} 
public void onContentChanged () { 
    System.out.println("onContentChanged"); 
    super.onContentChanged();   
} 
/* This function is called on each child click */ 
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,int childPosition,long id) { 
    System.out.println("Inside onChildClick at groupPosition = " + groupPosition +" Child clicked at position " + childPosition); 
    return true; 
} 

/* This function is called on expansion of the group */ 
public void onGroupExpand (int groupPosition) { 
    try{ 
     System.out.println("Group exapanding Listener => groupPosition = " + groupPosition); 
    }catch(Exception e){ 
     System.out.println(" groupPosition Errrr +++ " + e.getMessage()); 
    } 
} 

請即涉及到你的頭腦在這方面的任何解決方案給我。

回答

0

同時

輸出我下面的圖片的程序是:

enter image description here

+0

任何幫助在任的這是非常感謝! – user2261110 2013-04-18 09:16:10

相關問題