Joseph Malicke Joseph Malicke - 1 month ago 6
Android Question

What is the "built in TextView widget android:text1" and the "ListView widget android:id/list"?

An Android tutorial guide uses the following XML definitions and quotes:

<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>



This XML uses the built-in Android ListView widget android:id/list.


<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true />



This XML uses the built-in Android TextView widget android:text1.


First of all, I am used to seeing
id
properties defined like this:

android:id="@+id/list1"


What does it mean to use
@android:id/list
instead?

Second, what does
built-in ... widget
mean in this context?

Answer

These are ids defined in the Android SDK and which are used in some of the layout XML files provided by the Android SDK. You can refer directly to those ids in XML (e.g. android:id="@android:id/text1") or in Java (e.g. findViewById(android.R.id.text1) -- notice the fully-qualified name in java.

Some of these ids have special meaning in certain contexts. For example, if you are extending ListActivity or ListFragment, you must use android:id="@android:id/list" because those classes look for a ListView with that specific ID as part of their implementation. (If you don't provide a layout at all, those classes default to a layout with just a ListView in it.)

Note that you can still use these IDs outside of these special cases -- there's nothing preventing you from giving any view android:id="@android:id/list".