這是爲什麼是假?我無法得到它。 DataBaseHelper.getBoolean();是一個字符串值。在這個if語句中,它輸出相同的結果,但它表示它不相等。我沒有得到什麼。 String == String False
String a = DataBaseHelper.getBoolean(id);
String b = DataBaseHelper.getBoolean(id);
if (a==b){
newTextView.setText(DataBaseHelper.getBoolean(id) + " == " + DataBaseHelper.getBoolean(id) + " is TRUE \n");
} else {
newTextView.setText(DataBaseHelper.getBoolean(id) + " == " + DataBaseHelper.getBoolean(id) + " is FALSE \n");
}
從toher類的getBoolean方法。
public String getBoolean(int randomIndex) {
// TODO Auto-generated method stub
open();
Cursor c = myDataBase.query(TABLE_NAME1, columns, WHATTODONOW_COLUMN_ID
+ "=" + randomIndex, null, null, null, null);
if (c != null) {
c.moveToFirst();
String text = c.getString(8);
return text;
}
closee();
return null;
}
使用'=='比較字符串值將不起作用,請使用equals()方法。 – Geros
嘗試先搜索你的問題,然後問:) –