警告当宣布在Android中的字符串 [英] Warning when declare a string in android
问题描述
我只是问你一个简单的问题给你的专家,因为我刚开始学习Android的基础。
Im just asking you a simple question to you experts because i just started studying android basics.
我试图创建一个表视图,并在其中显示一些字符串。
I tried to create a table view and display some strings in it.
我写了这样的XML,但即时得到一些警告I18N]硬codeD字符串打开...,应使用@string
资源
当一个字符串声明。
i write the xml like this but im getting some warnings "I18N] Hardcoded string "Open...", should use @string resource" when a string is declared.
<TableRow>
<TextView
android:layout_column="1"
android:text="hello"
android:padding="3dip" />
<TextView
android:text="helloo"
android:gravity="right"
android:padding="3dip" />
</TableRow>
<TableRow>
<TextView
android:layout_column="1"
android:text="how"
android:padding="3dip" />
<TextView
android:text="Ctrl-Shift-S"
android:gravity="right"
android:padding="3dip" />
</TableRow>
<View
android:layout_height="2dip"
android:background="#FF909090" />
<TableRow>
<TextView
android:text="are"
android:padding="3dip" />
<TextView
android:text="you"
android:padding="3dip" />
</TableRow>
您可以帮我please.Thanks提前。
Can you please help me please.Thanks in advance.
推荐答案
字符串应该去这可能看起来像这样的 RES /价值/ strings.xml中
文件:
Strings should go to the res/values/strings.xml
file which could look like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World!</string>
<string name="app_name">My App</string>
<string name="ctrl-shift-s">Ctrl-Shift-S</string>
</resources>
应用程序可以很容易地进行本地化:在Eclipse中,右键单击资源文件夹,选择的 Android的XML值文件的,点击下一步。进入strings.xml中,单击下一步。现在,您可以添加各种选项,如语言或网络code。
Applications can be localized easily: In Eclipse, right-click the res folder, select Android XML Values File, click next. Enter strings.xml, click next. Now you can add various options like language or network code.
现在您可以通过引用您的字符串 @字符串/ CTRL-Shift-S键
。
Now you can reference your strings using @string/ctrl-shift-s
.
<TableRow>
<TextView
android:layout_column="1"
android:text="how"
android:padding="3dip" />
<TextView
android:id="@+id/textview-command"
android:text="@string/ctrl-shift-s"
android:gravity="right"
android:padding="3dip" />
</TableRow>
或者,爪哇code中, R.string.ctrl移-S
。
Or, within Java code, R.string.ctrl-shift-s
.
的 @ + ID / XYZ
创建了一个ID,这样你可以从code中的视图。
The @+id/xyz
creates an ID so you can get the view from code.
所有资源都被自动添加到研究
类。
All resources are being added to the R
class automatically.
TextView textView = (TextView) findViewById(R.id.textview-command);
if (textView != null)
textView.setText(R.string.ctrl-shift-s);
这篇关于警告当宣布在Android中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!