user547995
user547995

Reputation: 2085

Treemap and List View

Hy!

I have a Treemap and i want to set all strings in the map to the ListView

Code:

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));

My Problem is that the ArrayAdapter doesn't support a Set.

Are there any Solutions?

THX

Upvotes: 0

Views: 1189

Answers (1)

Daniel
Daniel

Reputation: 28104

Just create an ArrayList and all all the elements from the set. Pass this list.

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

Now use l. Or just create an Array:

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

EDIT: Added enhancement from comment.

EDIT2: Add @SupressWarnings("unchecked") to your function. I have to do this all the time when using external APIs that use pre-1.5 ungeneric code :).

Upvotes: 2

Related Questions