Leonti
Leonti

Reputation: 10960

Android - creating listview entirely from xml

I want to present some choices in my application. Right now I'm doing it with buttons one under another.

What I really want to do is to present them as a list like in "Settings" application. This boils down to creating a list with predefined values/choices. My problem is that I can't figure out how to do it with xml. I can add ListView to xml like this:

<ListView android:id="@+id/ListView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></ListView>

But how do I add entries to that? All examples I've found do it programatically - through cursor adapters or array adapters.

How do I create a list of textViews using XML only n Android? Does anyone know how it's done in "Settings" application and alike?

Thanks!

Upvotes: 12

Views: 10349

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006614

But how do I add entries to that? All examples I've found do it programatically - through cursor adapters or array adapters.

Use the android:entries attribute on your ListView element, pointing to a <string-array> resource (typically put in res/values/arrays.xml).

Upvotes: 17

Related Questions