Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between @id and @android:id

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ListView android:id="@android:id/list" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:layout_weight="1" />
    <Spinner android:id="@+id/section_spinner"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:layout_margin="5dp" />
</LinearLayout>

what is the difference between @android:id and @id in this case?

like image 649
denniss Avatar asked Mar 02 '12 08:03

denniss


People also ask

Is device ID same as Android ID?

All smartphones and tablets are identified by a unique device ID. The Android unique device ID is called the Android Advertising ID (AAID). It's an anonymized string of numbers and letters generated for the device upon initial setup. None of the user's personal information is included in an Android ID.

What's the difference between @ID and @+ ID?

The at-symbol (@) at the beginning of the string indicates that the XML parser should parse and expand the rest of the ID string and identify it as an ID resource. The plus-symbol (+) means that this is a new resource name that must be created and added to our resources (in the R. java file).

What is Android ID used for?

Android ID is an unique ID to each device. It is used to identify your device for market downloads, specific gaming applications that needs to identify your device (so that they know it's a device that was used to pay for the application) and such.

What is @ID in Android Studio?

android:id. Resource ID. A unique resource name for the element, which you can use to obtain a reference to the ViewGroup from your application.


2 Answers

The at-symbol (@) at the beginning of the string indicates that the XML parser should parse and expand the rest of the ID string and identify it as an ID resource. The plus-symbol (+) means that this is a new resource name that must be created and added to our resources (in the R.java file). There are a number of other ID resources that are offered by the Android framework. When referencing an Android resource ID, you do not need the plus-symbol, but must add the android package namespace.

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

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

The '+' means to create the symbol if it doesn't already exist. You don't need it (and shouldn't use it) when referencing android: symbols, because those are already defined for you by the platform and you can't make your own in that namespace anyway.

like image 99
Ajay Raval Avatar answered Sep 30 '22 16:09

Ajay Raval


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.

like image 28
waqaslam Avatar answered Sep 30 '22 16:09

waqaslam