【发布时间】:2015-08-08 12:28:58
【问题描述】:
我在 Android res/value 文件夹中的 string.xml 文件中有一个字符串数组,如下所示
我的字符串.xml
<string-array name="books_titles_en">
<item>Smoking Effeccts on Your Body</item>
<item>Smoking - effects on your body</item>
<item>How Tobacco Smoke Causes Disease</item>
<item>patterns of use, health effects, use in smoking cessation and regulatory issues</item>
</string-array>
我需要像这样检索数组的第一个元素
我的 home.xml
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/frag_1_text_pad"
android:textSize="@dimen/frag_1_text_size"
android:paddingRight="@dimen/frg_1_text_right_pad"
android:id="@+id/book_link0"
android:text="@string-array/book_title_en[0]"/>
我知道这似乎会导致错误。如何在 Android 中的 string.xml 中的字符串数组上检索这些东西
【问题讨论】:
-
不能正常这样做。
-
我们可以像 android:text="@string/app_name" 这样直接访问字符串,所以希望也有任何可用的方法。
-
@einschnaehkeee 我之前已经看到从字符串到数组的内容。我要求在我的另一个布局调用 home.xml 中将事物从数组获取到组件( TextView )
-
@NifrasIsmail 看到我的回答
标签: android arrays xml android-layout