2012-07-12 62 views
2

所以我有一個ExpandableListView。現在我在父列表中有3個項目。當我點擊其中一個時,子列表(子列表彈出)。我想要的是一個文本框顯示在下面,而不是一個列表。如何讓ExpandableListView中的孩子成爲文本框而不是Android的列表?

我想要一個父級列表,但爲孩子的文本框。我不知道如何做到這一點。這是我的代碼現在:

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

    SimpleExpandableListAdapter expListAdapter = 
     new SimpleExpandableListAdapter(
       this, 
       createGroupList(),    // Creating group List. 
       R.layout.group_row,    // Group item layout XML. 
       new String[] { "Group Item" }, // the key of group item. 
       new int[] { R.id.row_name }, // 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"},  // Keys in childData maps to display. 
       new int[] { R.id.grp_child}  // 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()); 
    } 
} 


//Create Headings of Assignment attributes 
private List createGroupList() { 
    ArrayList result = new ArrayList(); 

    //Create string array for Assignment Topic headings 
    String[] topics = {"1", "2", "3"}; 

    //Iterate through array of names to lay them out correctly 
    for(int i = 0 ; i < 3 ; ++i) { 

     HashMap m = new HashMap(); 
     m.put("Group Item", topics[i]); // the key and it's value. 
     result.add(m); 
    } 
    return (List)result; 

}

@SuppressWarnings("unchecked") 
private List createChildList() { 

    ArrayList result = new ArrayList(); 
    for(int i = 0 ; i < 3 ; ++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", "Sub Item " + n); 
     secList.add(child); 
     } 
    result.add(secList); 
    } 
    return result; 
} 

很顯然,我創建一個的childList時,我希望孩子成爲一個文本框。不知道如何實現這個壽命。任何幫助非常感謝!

+0

有沒有任何建議爲你工作? – prolink007 2012-07-16 17:39:48

回答

0

嘗試僅在「R.layout.child_row」中放置edittextview。如果它給出了一個錯誤再放置一個TextView也可做成invisible.I希望將解決problm

0

這很簡單,你應該創建一個名爲佈局:child_layout_row是這樣的...

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:layout_width="match_parent"> 
    <EditText android:id="@+id/text_edit_child" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" /> 
</LinearLayout> 

而不是R.layout.child_row,使用R.layout.child_layout_row就是這樣......

相關問題