简体   繁体   中英

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?

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.

Ie:

<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)

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM