androidlistviewhard-coding

Simple hard coded ListView in Android


Is it possible to do something like this in Android? (basically the equivalent of select and option in HTML):

<ListView android:layout_height="match_parent"
    android:layout_width="match_parent">
        <ListViewItem>TEST</ListViewItem>
        <ListViewItem>TEST1</ListViewItem>
</ListView>

I have tried this, it obviously doesn't work. All I can find online is information about using adapters, but as I have some hard coded values I don't need to use an adapter - I'm happy to put it directly in the XML file.

Is this possible?


Solution

  • 1 ] Create a String array in strings.xml

    2 ] Use the following attribute inside Listview tag android:entries="@array/your_array_name"

    Done !