D
D
Denis Karakchiev2015-09-15 21:02:52
Android
Denis Karakchiev, 2015-09-15 21:02:52

ListView does not accept string-array as entries, how to fix?

The task is to make the ListView display 3 elements from the string array:

<string-array name="options">
        <item>Drinks</item>
        <item>Food</item>
        <item>Stories</item>
    </string-array>

Instead, it displays what it began to display from the moment it was created (tried to create both through the GUI and through XML) (on the screenshot).
0f185082bb3141958ffc81c450b14936.png
The layout code itself:
<!--Начало кода стандартное-->

    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/list_options"
        android:entries="@array/options"/>


</LinearLayout>

UPD: When starting the emulator, everything works as expected on it. But the GUI looks the same. Therefore, the question remains, albeit a little simpler - where to hit the emulator so that it is already updated? =)
Screenshot of the emulator (this guy is great, it displays everything as expected)
9e8d745cc01c4320b77218d6a9f3858c.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SosnovschenkoR, 2015-09-15
@Satori_Kanzo

String[] entriesList = getResources().getStringArray(R.array.options);
ListView listView = (ListView)findViewById(R.id.listView1);
adapter = new ArrayAdapter(...,entriesList);
listView.setAdapter(adapter);
Probably something like this, well, put it in the required initialization section (for example, onCreate or onOptionsItemSelected)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question