escargot agile
escargot agile

Reputation: 22399

android.content.res.Resources$NotFoundException: File from xml type layout resource ID #0x1020014

I'm trying to use an ArrayAdapter in a ListActivity:

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. I'm using API 10. Can you help please?

Upvotes: 2

Views: 5400

Answers (2)

mrcktz
mrcktz

Reputation: 251

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). Put your TextView into this layout:

<?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<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.

Upvotes: 3

Sam
Sam

Reputation: 86958

You are using the wrong type of resource, you need to reference R.layout not R.id. Try android.R.layout.simple_list_item_1:

new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new String[] { "a", "b"});

Upvotes: 7

Related Questions