1

I am trying to create a ListView in android but it is only generating one item on the list.

Here is my code snippet

String[] kampala1 = getResources().getStringArray(R.array.kla);
sitelistview.setAdapter(new ArrayAdapter<String>(getApplicationContext(),
                        android.R.layout.simple_list_item_activated_1,kampala1));

i need help in getting all strings in the string array I created

string array is

<string-array name="kla"> 
   <item>uganda Museum</item>
   <item>Namugongo Museum</item>
   <item>wandegeya Market</item>
   <item>kasubi tombs</item>
   <item>kabaka palace</item>
   <item>kabaka lake</item>
</string-array>
Ashish Kudale
  • 1,230
  • 1
  • 27
  • 51

2 Answers2

0

if you want to use hard code string array then use it directly using xml.

Declare your array in strings.xml like this.

<string-array name="kla">
    <item>1</item>
    <item>2</item>
    <item>3</item>
    <item>4</item>
    <item>5</item>
    <item>6</item>
    <item>7</item>
    <item>8</item>
    <item>9</item>
    <item>10</item>

and use it in your layout.

 <ListView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/listView"
    android:entries="@array/kla"/>
Ashish Kudale
  • 1,230
  • 1
  • 27
  • 51
0

You could use an array Adapter. Its a good solution with ample scope for flexibility and customisation. Check the example explained in the solution below.

http://stackoverflow.com/questions/2453989/help-in-getting-string-array-from-arrays-xml-file

B.B.
  • 924
  • 2
  • 11
  • 28