开发者

Android element ID naming

开发者 https://www.devze.com 2023-03-10 01:10 出处:网络
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>

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号