如题,获取String.xml里面的资源的代码是Context.getString(R.string.xxx),但我想在获取之前做一次判断,判断xxx这个value是否存在于String.xml里面,求各位大神的解决办法~~

解决方案 »

  1.   

    将你的View aboutbutton ... 
     改成Button aboutbutton 
      

  2.   

    很简单  TextView tx = new TextView();
           tx.setText(R.String.XXX);       判断tx.getText()是否为空即可....
      

  3.   

    不行啊,改成Button后直接就红叉了。报错说是Button Cannot be resolved to a type
      

  4.   

    后来加了这样一个import android.widget.Button;不报错了。可是依然运行不出来,日志中还是一摸一样的错误。。
      

  5.   


    通过Button b = (Button)findViewById(R.id.about_button); 获得Button对象
      

  6.   


    MainActivity及需要跳转的AboutActivity  都需要在mainfest清单文件中申明
      

  7.   

    已经申明过了。这是我AndroidMainfest.xml文件。其中有两个Activity,第二个就是要跳转的Activity。
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.helloandroid"
        android:versionCode="1"
        android:versionName="1.0" >    <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="17" />    <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/activity_main_title"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.example.helloandroid.MainActivity"
                android:label="@string/continue_lable" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity
                android:name="com.example.helloandroid.AboutActivity"
                android:label="@string/about_title" >
            </activity>
        </application></manifest>
      

  8.   

    try {
      context.getString(R.string.xxx);

    catch (Exception e) {
       // no resource found.
    }
      

  9.   

    问题是如果string.xml里没有定义这个xxx字符串,在R文件里面是找不到这个id的啊,也就是eclipse会在R.string.xxx里面报错呀
      

  10.   

    哎呀...忘了   不存在  R.java文件就不会生成id值   编译是不会通过的