簡體   English   中英

在Android的ListView中添加子項

[英]add subitems in listview in android

我有一個listvew,並且像這樣的代碼將子項目添加到listview中

public class MyCustomListView extends Activity {
/** Called when the activity is first created. */
ListView lv;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.custom_list_view);
    lv=(ListView) this.findViewById(R.id.lvvv);      

    SimpleAdapter adapter = new SimpleAdapter(this,list, R.layout.custom_row_view,new String[] {"pen","color"},
            new int[] {R.id.text1, R.id.text3}
            );
    populateList(); 
    lv.setAdapter(adapter);
} 

static final ArrayList<HashMap<String,String>> list = 
    new ArrayList<HashMap<String,String>>(); 

private void populateList() {
    HashMap<String,String> temp = new HashMap<String,String>();
    temp.put("pen","MONT Blanc");       
    temp.put("color", "Black");
    list.add(temp);

    HashMap<String,String> temp1 = new HashMap<String,String>();
    temp1.put("pen","Gucci");
    temp1.put("color", "Red");
    list.add(temp1);

    HashMap<String,String> temp2 = new HashMap<String,String>();
    temp2.put("pen","Parker");
    temp2.put("color", "Blue");


}

}

但是在顏色鍵中,如果筆有很多顏色,並且我想將顏色排列到列表中,並且此顏色列表在筆下。

例如:

筆:帕克。

+顏色:藍色。

+顏色:紅色。

我該怎么辦? 請幫我! 非常感謝。

您需要使用ExpanadableListView。 看看這個-ExpanadaleListView教程

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM