0

How can I create a list in android and have static fields declared in the xml file, rather than create an adapter? which is how I would approach a dynamic list

4
  • 2
    you can you your strings in strings.xml and populate list from the array Commented Jan 10, 2014 at 11:23
  • 1
    It is better to read xml file and add to adapter Commented Jan 10, 2014 at 11:23
  • 1
    set your string in string array and populate it from that array. Commented Jan 10, 2014 at 11:24
  • 1
    it is impossible to use ListView without Adapter. Commented Jan 10, 2014 at 11:24

1 Answer 1

1

Define string array inside string.xml file inside res folder as like

<string-array name="arrayPaintMenu">
    <item>Circle (Stroke)</item>
    <item>Rectangle (Stroke)</item>
    <item>Circle (Fill)</item>
    <item>Rectangle (Fill)</item>
    <item>Line</item>
    <item>Free</item>
    <item>Text</item>
</string-array>

And inside your layout xml declare listview like this

<ListView
    android:id="@+id/myList"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:entries="@array/arrayPaintMenu" /> 

It will fill ListView automatically you not need to define Adapter for that ...working fine at my side hope you get success...

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

Comments

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.