比较.equals两个字符串()不工作

编程入门 行业动态 更新时间:2024-10-27 02:24:31
本文介绍了比较.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两个字符串()不工作

本文发布于:2023-11-29 01:40:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1644783.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   两个   工作   equals

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!