Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "@+id" mean?

Tags:

android

I've read through much of the Android documentation and I've yet to find any statement that says what an id value prefix of "@+id" means. I know what "@string" and variations of that mean, but not the variation with the "+". Besides giving me the answer, can you show me where in the Android docs this is documented?

like image 809
David M. Karr Avatar asked Nov 27 '10 18:11

David M. Karr


People also ask

What did ID stand for?

Identification/Identity/Identifier.

Does ID mean example?

ID is defined as an abbreviation for identification. An example of an ID is a driver's license.

What does ID mean from a girl?

ID means "identification". They are describing her as a fifteen-year-old female because they have no name for her because her identification was lost in the excitement of the emergency and getting her to the hospital.


2 Answers

The plus sign simply indicates that the ID should be created if it doesn't exist.

It's common practice to use @+id/foo when defining a new View in a layout, and then use @id/foo to reference the View from another part of the layout (say, in a RelativeLayout hierarchy) or R.id.foo to reference it from code.


UPDATE: Docs are here: Declaring Layout - Attributes - ID

like image 133
Roman Nurik Avatar answered Oct 06 '22 18:10

Roman Nurik


That's the syntax for linking an Android XML layout element to your Java code. So if I want to display text in a TextView, I have to do this.

Step one - define the layout

<TextView
android:id="@+id/SaveResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SaveResult"
android:layout_x="16px"
android:layout_y="190px"
>
</TextView>

Then, in code, I use @+id to link the layout to the variable. Think of the @+id as a foreign key in a database.

TextView lblSaveResult = (TextView)findViewById(R.id.SaveResult);

Now, it's ready for use. When I assign text, it uses the @+id to see where to put it, and also the color, size, etc..

lblSaveResult.setText("This text is now on the screen");

Sorry, but I don't know where the documentation is for this...

like image 45
tpow Avatar answered Oct 06 '22 19:10

tpow