English 中文(简体)
采用护卫
原标题:Using strings.xml w/ Android
  • 时间:2011-05-02 18:56:12
  •  标签:
  • java
  • android

I ve looked and tried many things but it seems my App isn t getting the values for strings in 座标. It actually seems like it s passing blank. I think there s an issue initializing.

座标

    <string name="itb_cityID">2</string>
        <string name="itb_city">New York</string>

不变。

public class ConstantData {

public static String cityID="2";
public static String city="New York";

How do I set cityID = R.strings.itb_cityID and city=itb_city 正确方式?

问题回答

String = Context.getResources().getString(R.string.your_string);

注:你可以静态使用<代码>。 如果你在某项活动中重新定位,则直接使用<条码>。 否则,你需要通过<条码>植被应用目录()获得与你的申请相关的操作。

这一榜样可能有用

  • XML file saved at res/values/strings.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <string name="hello">Hello!</string>
    </resources>
    
  • 这部文法适用于一种观点。

    <TextView
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:text="@string/hello" />
    
  • 该应用法可检索以下简称:

    String string = 获取String(R.string.hello);

    你可以利用String(int)或获得Text(int)来找寻护员,然后将保留适用于扼杀的丰富案文。

这个例子来自rel=“noreferer”http://developer.android.com/guide/topics/resources/string-resource.html

您核实整个项目都是没有错误的。 如果没有错误,则阻止R.java用你的话加以更新。 你可以尝试“项目”菜单中预测的“Clean”。 这可能行之有效。 此外,我也看看你为什么必须使用<条码>Context.,通常你们应该能够直接使用<条码>植被资源()。 如果你在座标书中宣布的扼杀物被确认为已宣布的扼杀物,那么可以看一看。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签