我正在尝试将 ContentValues 对象与数据库中的值进行比较,但我无法弄清楚为什么以下内容不起作用:
ContentValues werte = new ContentValues();
try{
JSONObject ClickedItem = new JSONObject();
ClickedItem = resultArray.getJSONObject(position);
werte.put("name", ClickedItem.getString("name"));
werte.put("hersteller", ClickedItem.getString("hersteller"));
}
catch (Exception e) {
System.out.println("Whoops - something went wrong!3");
e.printStackTrace();
}
Boolean allreadyAdded = false;
Cursor devicesCursor = mDatenbank.query("addedDevices", new String[] {"name", "hersteller"}, null, null, null, null, null);
startManagingCursor(devicesCursor);
devicesCursor.moveToFirst();
for (int i=0;i<devicesCursor.getCount();i++){
if(devicesCursor.getString(0) == werte.getAsString("name")){
allreadyAdded = true;
}
devicesCursor.moveToNext();
}
if(allreadyAdded==false){
mDatenbank.insert("addedDevices", null, werte);
}
只是不会工作,if(devicesCursor.getString(0) == werte.getAsString("name"))
我不知道为什么。System.out.println 向我展示了 devicesCursor 和 are 都具有相同的值,但已添加不会设置为 true...