2011-02-01 82 views
0

Hy!樹形圖和列表視圖

我有一個樹狀圖,我想在地圖中的所有字符串設定到ListView

代碼:

TreeMap<String, Integer> map = json.getChannels(lv.getItemAtPosition(arg2).toString()); 
ListView lv2 = new ListView(Channellist.this); 
Set st = map.keySet(); 
lv2.setAdapter(new ArrayAdapter<String>(Channellist.this,android.R.layout.simple_expandable_list_item_1,st)); 

我的問題是,一個ArrayAdapter不支持一組。

有沒有解決方案?

THX

回答

2

只需創建一個ArrayList和所有的一切從集合的元素。通過這個列表。

ArrayList<String> l = new ArrayList<String>(st); 

現在使用l。或者只是創建一個陣列:

String[] array = (String[])set.toArray(new String[st.size()]); 

編輯:添加增強從評論。

編輯2:將@SupressWarnings(「未選中」)添加到您的函數。在使用使用1.5之前的非代碼的外部API時,我必須一直這樣做:)。

+0

更好 - 「ArrayList l = new ArrayList(st)」,它會自動添加所有元素。 – 2011-02-01 18:08:44