Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of the asterisk (*) when referring to Android XML resources?

Tags:

android

What is the meaning of this Android code?

What is the difference between * ,+ and empty:

@*android:id

like this in android_ics/packages/apps/Setting/res/layout

<TextView android:id="@*android:id/timeDisplayForeground"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:ellipsize="none"
    android:textSize="@dimen/crypt_clock_size"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@color/crypt_keeper_clock_foreground"
    android:layout_alignLeft="@*android:id/timeDisplayBackground"
    android:layout_alignTop="@*android:id/timeDisplayBackground"
    android:layout_marginBottom="6dip" />
like image 335
Aaron Lee Avatar asked Jan 13 '23 20:01

Aaron Lee


2 Answers

The * allows you to access private resources. Private resources are private for a reason as their name could change in the future as part of a firmware or skin update.

It's not a good idea to use these resources unless you're working in an environment where you know these resources won't change and break your app in the future.

In your example, the private resources are being referenced by a system app which is where you'll most commonly see this * referencing used.

like image 127
Michael Celey Avatar answered Jan 16 '23 10:01

Michael Celey


I answered earlier but may have misunderstood your question. There is a generated file in your project called R.java which has your resources listed. For example, when you create your view and add buttons, you'll see some of that information going into your R.java file automatically. In Java, you access the information using these members. In XML however, you must access them by referencing the labels or nodes.

@android:id refers to the public system member called "id"
@id refers to one that you've created
@+id says to create one called "id" (and what to set it to)
@*android:id refers to a private system member

Refer to: http://developer.android.com/training/basics/firstapp/building-ui.html

like image 40
Dave Avatar answered Jan 16 '23 08:01

Dave