Android 设计视图未在列表视图中反映字符串数组的值
我在字符串资源文件中声明了一个简单的字符串数组,并希望在列表视图中填充它。在我的设备上测试应用程序时,一切正常。但是在androidstudio设计视图中,我得到了一些默认值,我想它们不是字符串资源文件中的值 我想知道这是一个小故障,bug还是我做错了什么 Strings.xmlAndroid 设计视图未在列表视图中反映字符串数组的值,android,listview,Android,Listview,我在字符串资源文件中声明了一个简单的字符串数组,并希望在列表视图中填充它。在我的设备上测试应用程序时,一切正常。但是在androidstudio设计视图中,我得到了一些默认值,我想它们不是字符串资源文件中的值 我想知道这是一个小故障,bug还是我做错了什么 Strings.xml <resources> <string name="app_name">Starbuzz</string> <string name="starbuzz_log
<resources>
<string name="app_name">Starbuzz</string>
<string name="starbuzz_logo">Starbuzz logo</string>
<string-array name="options">
<item>Drinks</item>
<item>Food</item>
<item>Stores</item>
</string-array>
</resources>
斯塔巴斯
Starbuzz标志
饮料
食物
商店
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.hfad.starbuzz.MainActivity">
<ImageView
android:layout_width="200dp"
android:layout_height="100dp"
android:src="@drawable/starbuzz_logo"
android:contentDescription="@string/starbuzz_logo"/>
<ListView
android:id="@+id/list_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/options">
</ListView>
</LinearLayout>
我相信您共享的屏幕是Android Studio中XML文件的预览,非常好。listview的预览将始终显示为默认模板。只有在emulator或实际设备上运行应用程序时,才会填充listview的数据项。我相信您共享的屏幕是Android Studio中XML文件的预览,这非常好。listview的预览将始终显示为默认模板。只有在emulator或实际设备上运行应用程序时,才会填充listview的数据项。其Android设计规则是,预览时只显示xml视图而不显示数据。因此,如果您希望在这里看到数据,您需要在设备或模拟器中运行它。它的Android设计规则是,它在预览中显示,只以xml呈现视图,而不使用数据。所以,如果您希望在这里看到数据,您需要在设备或模拟器中运行它。这只是列表数据吗?我可以看到其他文本和图像被渲染?是的,它仅用于列表,其他文本和图像将很容易渲染。至于使用列表,你需要有适配器为我清理它。要在下一个任务中学习适配器:)。非常感谢@ankit patidar!这只是列表数据吗?我可以看到其他文本和图像被渲染?是的,它仅用于列表,其他文本和图像将很容易渲染。至于使用列表,你需要有适配器为我清理它。要在下一个任务中学习适配器:)。非常感谢@ankit patidar!如果是android设计规则,则不应呈现该列表视图。有人能告诉我为什么会这样吗?如果这是android的设计规则,那么列表视图不应该被呈现。有人能告诉我为什么会这样吗?