tags:

views:

219

answers:

1

Hello everyone,

I've spent hours reading through the SDK reference, googling and reading tutorials - but I still can't figure it out.

I would like to know how to create a custom list item in the ListActivity widget on Android. Something similar to a Twitter client interface. Each list item has different types of text, possibly an icon, etc.

The issue is binding the data to the list item. If you define your own data structure, let's say "Tweet" which will store the message, author, date sent and a picture URL - how do you bind the tweet instance to the custom list item?

Does anyone know of any resources that would help me understand the process of creating something like that?

Any guidance would be appreciated. Thanks

+2  A: 

I'm not sure which tutorials you were reading but it's quite simple. You define your layout. You use it in your getView for your items. http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List14.html

you can also look at Mark's example with lazy loading images http://github.com/commonsguy/cwac-thumbnail

Alex Volovoy
The issue is binding the data to the list item. If you define your own data structure, let's say "Tweet" which will store the message, author, date sent and a picture URL - how do you bind the tweet instance to the custom list item?
Honza Pokorny
You override `getView()` for `ArrayAdapter`, or `newView()` and `bindView()` for `CursorAdapter`. See http://commonsware.com/Android/excerpt.pdf for a free excerpt from one of my books that covers the topic.
CommonsWare
in one of the methods Mark mentioned, you'll get the position of the item in your adapter. Then you get your item ( tweet ). Then for each member of your tweet class you'll find corresponding view - findViewById(R.id.tweetMessage) and set your value to that view.
Alex Volovoy