<?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?
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.
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).
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With