通过变量从Strings.xml获取字符串数组

时间:2017-10-11 15:59:27

标签: android

我尝试使用变量名来从 strings.xml 获取字符串。它工作得很好,但我希望使用变量访问string-array中的xml,但它无效。任何帮助将不胜感激

    String name = "app_name";
    int identifier = getResources().getIdentifier (name,"string","com.example.saa.quotes");
    if (identifier!=0){
        array=getResources().getString(identifier);
        Toast.makeText(this, array, Toast.LENGTH_SHORT).show();
    }
    else{
        array=null;//or null or whatever
        Toast.makeText(this, "Could not able to acces the Data", Toast.LENGTH_SHORT).show();
    }

0 个答案:

没有答案
相关问题