[英]android.content.res.Resources$NotFoundException: File from xml type layout resource ID #0x1020014
I'm trying to use an ArrayAdapter in a ListActivity: 我正在尝试在ListActivity中使用ArrayAdapter:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.id.text1, new String[] { "a", "b"});
setListAdapter(adapter);
This is the layout: 这是布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@id/android:text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" />
<ListView
android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="false"
android:layout_below="@id/android:text1" >
</ListView>
</RelativeLayout>
None of the solutions I found on StackOverflow seems to work. 我在StackOverflow上找到的解决方案似乎都不起作用。 I'm using API 10. Can you help please?
我正在使用API 10.你能帮帮忙吗?
You are using the wrong type of resource, you need to reference R.layout
not R.id
. 您使用的是错误类型的资源,需要引用
R.layout
而不是R.id
Try android.R.layout.simple_list_item_1
: 试试
android.R.layout.simple_list_item_1
:
new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new String[] { "a", "b"});
Define a layout for the rows of your ListView, and call it, for example, simple_list_item_1
(create the file simple_list_item_1.xml
in the folder res/layout
). 为ListView的行定义布局,并调用它,例如,
simple_list_item_1
(在文件夹res/layout
创建文件simple_list_item_1.xml
)。 Put your TextView
into this layout: 将
TextView
放入此布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@id/android:text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" />
</RelativeLayout>
and then create your ArrayAdapter like this: 然后像这样创建ArrayAdapter:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.simple_list_item_1, R.id.text1, new String[] { "a", "b"});
Here you'll find a detailed explanation about Lists and Adapters. 在这里,您将找到有关列表和适配器的详细说明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.