本文介绍了比较.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两个字符串()不工作
发布评论