Can one not use @+id with ArrayAdapter layout XML file?

by blindfold » Sun, 28 Dec 2008 17:03:56 GMT

Sponsored Links
 Not using @+id through

ArrayAdapter<String> MyList = new ArrayAdapter<String>(this,

works fine, but using @+id through

ArrayAdapter<String> MyList = new ArrayAdapter<String>(this,;

does not, where my mylist.xml reads

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="" ;

It all compiles just fine, but at runtime I get

ERROR/AndroidRuntime(1356): android.content.res.Resources
$NotFoundException: Resource ID #0x7f06001a type #0x12 is not valid

Am I missing some conceptual issue with the use of ArrayAdapter or the
way @+id gets expanded? Of course I can just use R.layout.mylist, but
it feels a bit inconsistent as I use the referencing in my source
code with many other items (albeit through findViewById()).



Can one not use @+id with ArrayAdapter layout XML file?

by Mark Murphy » Sun, 28 Dec 2008 21:07:53 GMT


R.layout points to layout resources. Layout resources are used whenever
Android wants to inflate a tree of Views, such as setContentView(),
manual inflation via getLayoutInflater(), etc. points to individual widgets (Views) within an inflated layout. values have no meaning outside the context of a specific layout --
in other words, means nothing on its own, but
myInflatedView.findViewById( might, if myInflatedView was
inflated from a layout resource that had something with

In the documentation for the ArrayAdapter constructor you're using, the
second parameter is described as:

"The resource ID for a layout file containing a TextView to use when
instantiating views."

Hence, it is expecting something in the R.layout space ("resource ID for
a layout file").

Mark Murphy (a Commons Guy) 
_The Busy Coder's Guide to Android Development_ Version 1.9 Available!


Sponsored Links

Can one not use @+id with ArrayAdapter layout XML file?

by blindfold » Mon, 29 Dec 2008 08:42:50 GMT

 Thanks a lot for your clarification, Mark! Very lucid.



Other Threads

1. Virtual keypad in landscape mode

Hi ,
    I am working currently on an application which is in landscape
mode by default. I want the virtual kepad to be poped up whenever I
click on the edit box. Please, help me for the same.


2. about android power

When I put android cupcake source code compiled after porting to 6410
board will always be an infinite cycle of this message, no way to
enter into the sleep state I ask where should I start with to solve

[CMM_Open] instanceNo : 0
s3c_g2d_open() <<<<<<<< NEW DRIVER >>>>>>>>>>>>>>
[CMM_Open] instanceNo : 1
s3c_g2d_open() <<<<<<<< NEW DRIVER >>>>>>>>>>>>>>

android_power: wakeup (0->0) at 4362616001000 (2001-01-19
14:09:00.800694000 UTC)

binder: 1783:1783 transaction failed 29189, size 168-0



android_power: wakeup (0->0) at 4363500661000 (2001-01-19
14:09:01.685352000 UTC)


3. Launching an external activity from a widget

4. K9 mail view by thread

5. about android wifi dhc

6. Ubuntu Karmic 64-bit build notes

7. Overriding Animation setting