我想比較我的結果(字符串),我使用下面的代碼來檢查它。String.equal()函數不能與`R.string`的值一起工作
result = "password";
if (result.equals(R.string.myResponse)) {
//do something
}
R.string文件
<string name="myResponse">password</string>
上述功能無法正常工作,並且不進入if
一部分。 但是,如果我用if(result.equals("password"))
替換R.string.myResponse
及其實際值,那麼它工作正常。
從什麼R.string
您是否嘗試過使用調試器? – Jens
嘗試'if(result.equals(getString(R.string.myResponse)))' – daco
'R.string.myResponse'將返回整數給你。 – SripadRaj