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,
R.layout.mylist);

works fine, but using @+id through

ArrayAdapter<String> MyList = new ArrayAdapter<String>(this,
R.id.mylist);

does not, where my mylist.xml reads

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android=" http://schemas.android.com/apk/res/android" ;
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:gravity="center_vertical"
    android:paddingLeft="6dip"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:id="@+id/mylist"
/>

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 R.id referencing in my source
code with many other items (albeit through findViewById()).

Thanks

--~--~---------~--~----~------------~-------~--~----~



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.

R.id points to individual widgets (Views) within an inflated layout.
R.id values have no meaning outside the context of a specific layout --
in other words, R.id.fu means nothing on its own, but
myInflatedView.findViewById(R.id.fu) might, if myInflatedView was
inflated from a layout resource that had something with
android:id="@+id/fu".

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)
 http://commonsware.com 
_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.

Regards





--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. com.android.internal

Dear Developers !

I am developing an Application for one of the OEM. And I need to
import com.android.internal classes to new namespace. Yes, I have full
access to android OS and building full ROM flash image.

I do not get any compile time error, but as soon as I launch the app,
I get run-time exception (class not found).

Is there a specific way to import android internal classes ?

Thanks

-- 
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

2. for loop drawing first graphics to x0 y0 if more than 1 iteration

Anyone have any idea why when i run this for loop to add a graphic to
my screen, the first iteration coordinate get discarded if the loop
runs more than once?

 For Example, I have a column of 7 graphics in a graphic array list,
when I remove a graphic the code below runs to insert a new graphic,
and it works perfectly if there is only 1 graphic removed/added. The
problem is when I remove 2 or more graphics from the column, the first
1 that is readded get written to x0 and y0 instead of x64 y64 but the
second graphic is correctly added to x64 y128. I am using OnDraw
canvas to draw.

I am totally stumped with this one, if anyone has any insight on to
why this may be happening please HELP ME?? Thanks a bunch.

                          if(_theGrid1.size()<7){
                                int g1left = 7-_theGrid1.size();
                                        int i;
                                        for(i=1;i<=g1left;i++){
                                                x1=64;
                                                y1=i*64;
                                                
graphic.getGridCoordinates().setGrid1X(x1);
        
graphic.getGridCoordinates().setGrid1Y(y1);

                                                _theGrid1.add(0,_toAdd.get(0));
                                                
_theGrid1.get(0).setAMT(_theGrid1.get(0).getAMT()
+g1left);
                                                _toMove.add(_toAdd.get(0));

                                                _theGrid1.get(0).setMV(i+10);

                                                _toAdd.remove(_toAdd.get(0));
                                        }


-- 

3. Android Market Licensing Problem

4. Update x10

5. Tracking revenue on the Android Market

6. The proliferation of Android markets.

7. Cross Promotion of app