12

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!

1 Answer 1

17

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! Is there a way to use views as entries? For example I want every entry to be image + textView + possibly checkbox.
@Leonti: Well, yes, but you have to "do it programatically - through cursor adapters or array adapters".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.