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
-
2you can you your strings in strings.xml and populate list from the arrayRaghunandan– Raghunandan2014-01-10 11:23:39 +00:00Commented Jan 10, 2014 at 11:23
-
1It is better to read xml file and add to adapterRiskhan– Riskhan2014-01-10 11:23:59 +00:00Commented Jan 10, 2014 at 11:23
-
1set your string in string array and populate it from that array.Piyush– Piyush2014-01-10 11:24:53 +00:00Commented Jan 10, 2014 at 11:24
-
1it is impossible to use ListView without Adapter.Tamilselvan Kalimuthu– Tamilselvan Kalimuthu2014-01-10 11:24:57 +00:00Commented Jan 10, 2014 at 11:24
Add a comment
|
1 Answer
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...