What Is Difference Between @+Id/Android:List and @+Id/List

What is difference between @+id/android:list and @+id/list

Resource IDs in Android are specific to a package (which is good, or else you'd have lots of conflicts if your app is dealing with several packages at the same time).

@+id/list will create a resource ID in your app (=your package) with the name "list" and give it a unique ID. In code, that would be R.id.list.

@android:id/list will use the ID "list" from the package android (which, in code, would be android.R.id.list.

EDIT: Need to add the corrections David Hedlund pointed out: The proper reference would be @android:id/list. Also, + indicates you're defining a new ID - you obviously don't need that when you're referencing something that was defined in the Android API.

difference between @id and @android:id

You need to use @+id when you are defining your own Id to a view, which in this case is section_spinner. And @android:id is used when you need to set an Id of a view to android's pre-defined Id in framework. for e.g when using ListActivity, TabWidget/FrameLayout in TabHost and etc.

what's different @android:id/list @+id/android:list?

@+id/test means you are creating an id named test in the namespace of
your application. You can refer to it using @id/test.

@android:id/test
means you are referring to an id defined in the android namespace.

Difference between @id/ and @+id/ in Android

you refer to Android resources , which are already defined in Android system, with @android:id/.. while to access resources that you have defined/created in your project, you use @id/..

More Info

As per your clarifications in the chat, you said you have a problem like this :

If we use android:id="@id/layout_item_id" it doesn't work. Instead @+id/ works so what's the difference here? And that was my original question.

Well, it depends on the context, when you're using the XML attribute of android:id, then you're specifying a new id, and are instructing the parser (or call it the builder) to create a new entry in R.java, thus you have to include a + sign.

While in the other case, like android:layout_below="@id/myTextView" , you're referring to an id that has already been created, so parser links this to the already created id in R.java.

More Info Again

As you said in your chat, note that android:layout_below="@id/myTextView" won't recognize an element with id myTextViewif it is written after the element you're using it in.

@id/android:list vs. @android:id/list in Android Layout XML

Functionally I belive the the two are equivlant and will both look for android.R.id.list.
They are just saying the same thing in a different way.

Resources in android are package specific. Saying @id/android:list will look for the list id within the android package. In this version, the package you are looking in is indicated by the :. In the second example @android:id/list you are defining the package first, the android package, and then telling it to look for id/list within that package.

This works just as it would were you to say @string/whatever or @id/blah. In those instances the system would look within your applications package for that resource. By placing android first, you're just telling it to look in the android package for those resources and not within your own applications resources folder.

I think this post also answers your question. It has some more detailed comments as well that might be helpful.

Using android:id=android:id/list

If you use ListFragment or ListActivity you don't have to give a view, and Android has already a predefined view and an id to find it which it does automatically. Here the dev adds some stuff but to still use the ListFragment or ListActivity features, he uses the same id.

More info in ListFragment.

Android: id list view

Your ListView object id should be specified either as android:id="@android:id/list"

ListView lv = (ListView) findViewById(android.R.id.list);

or it should have some other id like android:id="@+id/sampleList"

ListView lv = (ListView) findViewById(R.id.sampleList);

Check this : ListActivity

and list

Hope this would help.



Related Topics



Leave a reply



Submit