Android element ID naming
So I have a stri开发者_JAVA百科ng in my strings.xml file declared like so:
<string name="welcome">Please hit the menu to begin</string>
And I have a TextView in my main.xml that uses it like so:
<TextView
android:id="@string/welcome"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/welcome"
/>
Now, is that the proper way to give a TextView an ID? It seems strange to use a string resource as an ID like that.
Now, is that the proper way to give a TextView an ID?
No. Use android:id="@+id/whatever"
.
To add an id directly to a textview you must append a + sign
android:id="@+id/welcome"
alternatively you can have an id set up in a resource file
<resources>
<item name="welcome" type="id"/>
</resources>
android:id="@id/welcome"
http://developer.android.com/guide/topics/ui/declaring-layout.html is the manual page related to this topic
精彩评论