Can a string-array be attached to a ListView by default?

If I have a string-array defined in my strings.xml file.

<string-array name="items">
    <item >item 1</item>
    <item >item 2</item>
    <item >item 3</item>
</string-array>

Could I use a reference to plug it straight into my ListView?

<ListView
    android:id="@+id/itemsListView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    - reference to items here >
</ListView>

Or is this only possible using an adapter in the code?

Answers


From the official documentation:

So use the android:entries attribute on your ListView element, pointing to a <string-array> resource [ put your array in res/values/arrays.xml]

But if you have to customise your items (using ImageView, checkbox...) you have to do it programmatically using cursor adapters or array adapters.

Adapter are an interface between a source of data and ui component each time you have to fill listview, gridview, gallery, spinner etc you have to use adapters


Use android:entries for element and refrences your <string-array>

and create(res->value->array.xml)


Need Your Help

How to create a program that asks user to enter "up to" 20 integers and uses parameter passing to functions to output the max, min, and average value?

c arrays function parameter-passing

For an assignment I need create a program in C that uses arrays and functions and prompts the user to enter up to 20 integers to find the min, max, and average values. So far I have a program that ...

Pass parameters to event in a loop

c# winforms events event-handling parameter-passing

I have loaded some Picturebox with image location from database, I would like to pass parameters (price and name) to click event handler in a loop