![](/img/trans.png)
[英]android.content.res.Resources$NotFoundException: File res/layout/action_menu_layout.xml from xml type layout resource ID #0x109001b
[英]android.content.res.Resources$NotFoundException: File from xml type layout resource ID #0x1020014
我正在嘗試在ListActivity中使用ArrayAdapter:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.id.text1, new String[] { "a", "b"});
setListAdapter(adapter);
這是布局:
<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>
我在StackOverflow上找到的解決方案似乎都不起作用。 我正在使用API 10.你能幫幫忙嗎?
您使用的是錯誤類型的資源,需要引用R.layout
而不是R.id
試試android.R.layout.simple_list_item_1
:
new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new String[] { "a", "b"});
為ListView的行定義布局,並調用它,例如, simple_list_item_1
(在文件夾res/layout
創建文件simple_list_item_1.xml
)。 將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>
然后像這樣創建ArrayAdapter:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.simple_list_item_1, R.id.text1, new String[] { "a", "b"});
在這里,您將找到有關列表和適配器的詳細說明。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.