Reputation: 2552
What does it mean to set the android:text
attribute of a view in a layout xml file to something like @+id/xyz
. An example can be found at https://github.com/freezy/android-xbmcremote/blob/master/res/layout/actor_item.xml
Relevant code copied here:
<TextView
android:text="@+id/actor_name"
android:id="@+id/actor_name"
android:textColor="#ffffff"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="@+id/actor_role"
android:id="@+id/actor_role"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Upvotes: 1
Views: 163
Reputation: 5260
please visit http://developer.android.com/guide/topics/ui/declaring-layout.html#id
The plus (+) sign just indicates it that the ID should be created if it is not under existence at the moment.
It is a general practice to use @+id/something when defining a new View in a layout, and then later use @id/something to reference the View from another part of the layout (say, in any RelativeLayout ) or R.id.something to reference it from our java code.
Upvotes: 0
Reputation: 2057
"@+id/id" means you are giving a unique name or id for textview
which will help to identify that textview
and android:text
is like body of the textview
u can give anything which u want to display.
Upvotes: 1
Reputation: 849
"android:text" requires to set String to it. It's the text that will appear in the TextView.
You can either use a plain string or use @string to extract the string from res/values/strings.xml
<TextView
android:text="@string/actor_name"
android:id="@+id/actor_name"
android:textColor="#ffffff"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
"@+id/id" is a kind of action that tells the android framework to create an id. The plus symbol, +, indicates that this is a new resource ID and will be created if doesn't exist.
Upvotes: 0
Reputation: 43023
That doesn't make much sense. According to documentation what you assign to android:text
must be a string value:
Must be a string value, using
\\;
to escape characters such as\\n
or\\uxxxx
for a unicode character.This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.
Values of @id
are integers.
Upvotes: 1