Search code examples
androidlistviewvarying

Android: how do I create a listview screen with different content for each row


I'm looking to create a listview screen similar to the Sound Setting screen (in the built in Settings app, see image below), i.e I want some rows to have text + checkboxes, other rows to have text + "pop up" buttons, some rows should have text only etc.

What is the best way to accomplish this?

alt text


Solution

  • That's not a listview, that's a PreferenceActivity. Take a look at the PrefereceActivity class

    http://developer.android.com/reference/android/preference/PreferenceActivity.html

    If you really want to have a different view for each row in a listview (which is very valid), you'll have to create your own class that extends BaseAdapter. In the getView() method, just return the view you want to show. There are plenty of examples online.