Hey, I’m currently having trouble with a small Android application I’m making. What I’m attempting to build is:
- A list interface with
- Each row having two TextViews (a title and a caption).
- Have the values of these to be drawn from two separate string array resources.
The interface has the following text views in rowLayout.xml,
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:orientation="vertical">
<TextView android:text="@+id/rowTitle"
android:layout_height="wrap_content"
android:id="@+id/title"
android:textSize="25px"
android:layout_width="match_parent">
</TextView>
<TextView android:text="@+id/rowCaption"
android:layout_height="wrap_content"
android:id="@+id/caption"
android:textSize="25px"
android:layout_width="match_parent">
</TextView>
and the string resources are,
<string-array name="menuEntryTitles">
<item>Start</item>
<item>Stop</item>
</string-array>
<string-array name="menuEntryCaptions">
<item>Starts the update listener service.</item>
<item>Stops the update listener service.</item>
</string-array>
There should be two rows titled Start and Stop and each has their relevant captions. I’ve attempted using an ArrayAdapter to implement this,
ArrayAdapter listAdapter = ArrayAdapter.createFromResource(this,
new int[] {R.array.menuEntryTitles, R.array.menuEntryCaptions},
new int[] {R.id.rowTitle, R.id.rowCaption});
but I’m getting errors due to createFromResource requiring int arguments when I can only provide int[].
Hope someone here can point me in the right direction.
Cheers
One solution is to create your own adapter since ArrayAdapter only uses one array, and not two.
You can create the adapter as a private class within you ListActivity. Try something like this (warning: code not tested):