views:

60

answers:

2

I saw it used in textview and webview

android:id="@+id/textview"
android:id="@+id/webview"

but looks like there is none for DigitalClock widget.

So, when do I have to use it? Just for text and web views?

+3  A: 

No. That kind of identifiers are customizable by the programmer. It's used to reference the Views from the Java code. For instance:

TextView foo = (TextView) findViewById(R.id.textview);

Of course, you can use any name you want. For example:

android:id="@+id/whatever_you_want"

Will be referenced this way:

TextView foo = (TextView) findViewById(R.id.whatever_you_want);

Another thing to bear in mind is that there are some IDs that are reserved. Any way, you will recognize user-created IDs because they contain a plus (+): @+id/whatever

Cristian
+1  A: 

You use it when you need it, either to:

  • Reference it from Java (R.id.whatever)
  • Reference it from elsewhere in your layout (see RelativeLayout)
CommonsWare