简体   繁体   中英

R.string comparison

I am trying to compare a simple string from the R.string class but something is wrong.

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?

R.string.stop_track is an int identificator of your string, not it's value. 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)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM