比较.equals两个字符串()不工作 [英] compare two strings with .equals() don't work

查看:187
本文介绍了比较.equals两个字符串()不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到一个字符串,形成一个列表,并尝试将其与价值观一些字符串比较,然后做一些东西。

I get a string form a list and try to compare it with some strings in the values and then do some stuff

for(int i=0; i<sizeOfList; i++){

    String LIST_TITLE;

    LIST_TITLE = list_title.get(i); //the List list_title includes some strings

    if(LIST_TITLE.equals(R.string.percentbattery)) {
        //do stuff
        Log.d("EQUAL!","" + LIST_TITLE);
    } else if(LIST_TITLE.equals(R.string.screenrecorder) == true) {
        //do stuff
        Log.d("EQUAL!","" + LIST_TITLE);
    } else if(LIST_TITLE.equals(R.string.eightsms) == true) {
        //do stuff
        Log.d("EQUAL!","" + LIST_TITLE);
    } else {
        // do stuff
        Log.e("TITLE NOT EQUAL","" + LIST_TITLE);
    }
}

如果我比我的LIST_TITLE的(R.string ......)我在LogCat中他们是平等的,但我从else语句只得到TITLE不等于记录。

If I compare my LIST_TITLE with the (R.string. ...) in my Logcat they are equal, but I get only the "TITLE NOT EQUAL" Log from the else statement.

有另一种方式来比较这些字符串?在==方法也不起作用。

Is there another way to compare these strings? the "==" method also don't work.

推荐答案

R.string.percentbattery 不是一个字符串,它是一个整数,它的ID引用字符串。

R.string.percentbattery is not a String, it's an Integer that is the ID to reference the string.

ü希望的是:

LIST_TITLE.equals(context.getResources.getString(R.string.percentbattery))

这篇关于比较.equals两个字符串()不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆