【发布时间】:2011-05-25 15:25:55
【问题描述】:
嘿,我目前正在制作一个小型 Android 应用程序时遇到问题。我正在尝试构建的是:
- 列表界面
- 每行有两个 TextView(一个标题和一个标题)。
- 从两个单独的字符串数组资源中提取这些值。
界面在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>
字符串资源是,
<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>
应该有两行标题为“开始”和“停止”,每行都有相关的标题。我尝试使用ArrayAdapter 来实现这一点,
ArrayAdapter listAdapter = ArrayAdapter.createFromResource(this,
new int[] {R.array.menuEntryTitles, R.array.menuEntryCaptions},
new int[] {R.id.rowTitle, R.id.rowCaption});
但由于createFromResource 需要int 参数而我只能提供int[] 时出现错误。
希望这里有人能指出正确的方向。
干杯
【问题讨论】:
标签: android android-layout android-listview textview