Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Adding Secondary Data with a SimpleAdapter - How do you know to use text1 and text2?

In the video there is a set of lines where we do this:

int[] ids = {android.R.id.text1,android.R.id.text2};
SimpleAdapter simpleAdapter = 
new SimpleAdapter(this, blogPosts, android.R.layout.simple_list_item_2,keys,ids);

I get that the keys map to the HashMaps, and ids map to the ids of the ListView. However what I don't get is how did you know its text1 and text2 that you use, instead of some other android id?

Thanks! -Kunal

2 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

There is not a good answer for this. In fact, I would like to write a blog post about it because there isn't really a good resource. Really, what you need is the actual layout XML for android.R.layout.simple_list_item_2. You can either download the Android source code and search for it or Google "android.R.layout.simple_list_item_2" and find the source posted online somewhere. Once you have that you can see what keys to use and where they will be displayed.

The other way is to look for example code and make inferences off of that. You have to be careful about guessing how example code works, but this is a safe example because you can map out how values get displayed pretty easily.

Thanks, this is good to know. I thought I was missing something conceptually in how it maps.