Lawrence Gimenez
Lawrence Gimenez

Reputation: 3237

TabHost and TabWidget android:id

I have noticed in my main.xml layout, I'm creating a Tab Layout, that the declaration of "android:id" is different from what I've used for button, textview, etc.

For example:

<TabWidget android:id="@android:id/tabs" />

and example on Buttons:

 <Button
    android:id="@+id/button_next" />

What is the difference of the two declarations?

Upvotes: 1

Views: 764

Answers (3)

Shreyash Mahajan
Shreyash Mahajan

Reputation: 23596

blessenm is right. While we load the application it will search for the default id that are created by the android framework. and second one is the is that we use to define it just for our application purpose only.

The first one is use for all the application but the second one is use only for that perticular application.

Hope you got the point. Thanks.

Upvotes: 1

blessanm86
blessanm86

Reputation: 31779

Certain id's are used by the android framework. Like tabwidget,list etc. When the activity is launched it finds its required elements by searching the layout for these id's.

But when you are setting and id to a view for your own apps purpose, you only use id/yourid. This is only going to be used by your application code.

Upvotes: 1

WilHall
WilHall

Reputation: 11984

When you assign an ID like so:

<Button
    android:id="@+id/button_next" />

You are creating a new resource ID in your project's resources in the R.java file.

When you assign an id that is prefixed with @android:id, you are referencing a resource that exists in the android namespace.

I.e:

<TabWidget android:id="@android:id/tabs" />

In this case, you assign the id @android:id/tabs to the TabWidget, because it allows for your instance of TabWidget to inherit from an existing resource in the android namespace.

See this page for more info on the different ID assignments (scroll to the Attributes section)

Upvotes: 2

Related Questions