I have a TreeMap with key value pairs, The key is a String which denotes a certain type. Based on this there can be four more properties of the type which I add as a list. Now for each entry of <|key|,list |string> I want to populate one single row in the list view. What type of Adapter should I make. Also I have to keep in view that I have to override the getView() method because I want to display different pictures depending on the key value. Any Hints or tutorials?
Asked
Active
Viewed 662 times
0
-
Are you using TreeMap or hashMap?? – SweetWisher ツ Dec 12 '13 at 09:17
-
A TreeMap, to keep my keys sorted. – User3 Dec 12 '13 at 09:19
-
Have a look on [this](http://stackoverflow.com/a/18546016/2591002) – SweetWisher ツ Dec 12 '13 at 09:19
2 Answers
0
You can use simple base adapter..In that adapter, in get view method, u can use another list adapter to inflate that list

SweetWisher ツ
- 7,296
- 2
- 30
- 74
-
-
-
Yes I know that, I described that in the Question itself. But how do I assign the list items to a single row? And then repeat? – User3 Dec 12 '13 at 09:29
-
I just got a divine vision, I can convert this whole treemap into a list! preserving the sort order! – User3 Dec 12 '13 at 09:30
-
you want something like second level of listview if i am not getting you wrong – SweetWisher ツ Dec 12 '13 at 09:30
-
@user2822178 Well, if you can do it yourself, then why ask the question in the first place? – Aleks G Dec 12 '13 at 09:51
0
You can easily get away with using BaseAdapter
. The trick here is to get a key-value pair from the map at the specified index. This isn't that difficult - and with your map being sorted you'll get the same order every time. You'll have something like this:
public class MapAdapter<K, V> extends BaseAdapter {
Context context;
Map<K, V> data;
public MapAdapter(Context _context, Map<K, V> _data) {
context = _context;
data = _data;
}
public int getCount() { return data.size(); }
public Object getItem(int position) {
K key = map.keySet().toArray()[position];
V value = map.get(key);
return AbstractMap.SimpleEntry(key, value);
}
public View getView(int position, View convertView, ViewGroup parent) {
AbstractMap.SimpleEntry<K, V> entry = (AbstractMap.SimpleEntry<K, V>)getItem(position);
K key = entry.getKey();
V value = entry.getValue();
MyRowView rowView = (MyRowView)convertView;
if(rowView == null) {
rowView = ... //create your view by inflating or otherwise
}
//Now you have the view and details of your key and value - populate the row
...
return rowView;
}
}

Aleks G
- 56,435
- 29
- 168
- 265