Search code examples
androidandroid-layoutandroid-xmlr.java-file

Android: Why would we need to reference a resouce ID from Android Package namespace in XML?


From the developer guide,

When referencing an Android resource ID, you do not need the plus-symbol, but must add the android package namespace, like so:

android:id="@android:id/empty

This got me wondering why would we need to refer to a resource ID from the android package namespace in XML? So can you give me example(s) ?


Solution

  • One example is the one you quoted from in the documentation, identifying the empty view to use for a ListActivity.

    Quoting the "Screen Layout" section of the ListActivity JavaDocs:

    ListActivity has a default layout that consists of a single, full-screen list in the center of the screen. However, if you desire, you can customize the screen layout by setting your own view layout with setContentView() in onCreate(). To do this, your own view MUST contain a ListView object with the id "@android:id/list" (or list if it's in code)

    Optionally, your custom view can contain another view object of any type to display when the list view is empty. This "empty list" notifier must have an id "android:id/empty". Note that when an empty view is present, the list view will be hidden when there is no data to display.