[英]R.string comparison
I am trying to compare a simple string from the R.string class but something is wrong. 我正在尝试比较R.string类中的一个简单字符串,但是出了点问题。
if(this.b1.getText().equals(R.string.stop_track))
The b1 text is equals to stop_track text, why I'm getting a false result? b1文本等于stop_track文本,为什么我得到错误的结果?
R.string.stop_track
is an int
identificator of your string, not it's value. R.string.stop_track
是字符串的int
标识符,而不是它的值。 Try to use this line of code: 尝试使用以下代码行:
if(this.b1.getText().equals(getString(R.string.stop_track)))
R.string.stop_track
本身只是一个整数形式的引用。
由于R.string.stop_track
返回一个整数,因此出现错误,因此,编写下面的代码代替您的代码,它将解决您的问题。
if(this.b1.getText().toString().equals(getResources().getString(R.string.stop_track)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.