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. can we assure that Application#onCreate always runs before the Provier#onCreate and Activity#onCreate

I wouldn't count on one or the other.  For your problem, just have a global
singleton for accessing the data, and retrieve that everywhere you need it.
The first one who gets it will initialize it.

Dianne Hackborn
Android framework engineer

Note: please don't send private questions to me, as I don't have time to
provide private support.  All such questions should be posted on public
forums, where I and others can see and answer them.


2. CacheManager.CacheResult

Has anyone been able to create a valid CacheResult object manually?  I
am using UrlInterceptHandler to return custom cached html pages.  The
instance variables of CacheManager.CacheResult are accessible within
the android.webkit package only.  And as far as I can tell there is no
way to set the mimeType of a CacheResult object.  I went through the
code from the Android Open Source Project and it looks like the
android webkit caching code accesses the instance variable directly
rather than through the getters.  So I could not even use a custom
CacheResult object.

Has anyone been able to use UrlInterceptHandler successfully?

I also saw that there is a method call CacheManager.createCacheFile
but it is not available in the Android 1.0 r1 sdk.    Will this be
available soon?


3. android htc touch HD

4. Recorder Audio

5. Require Source code of tools

6. Importing Jars

7. Android SW development request