Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - creating listview entirely from xml

Tags:

android

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!

like image 445
Leonti Avatar asked Jul 10 '10 21:07

Leonti


1 Answers

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).

like image 74
CommonsWare Avatar answered Nov 17 '22 04:11

CommonsWare