I have this code :
private void insertValus() {
ContentValues initialValues = new ContentValues();
for (int i = 0 ; i < COUNTRIES.length ; i++){
Character tmp = (Character)COUNTRIES[i].charAt(0);
initialValues.put(VALUE, COUNTRIES[i]);
initialValues.put(TYPE, "country");
initialValues.put(LETTER,tmp.toString(tmp));
db.insert(TABLE_NAME, null, initialValues);
}
}
public boolean existInDataBase(String userChoice) {
boolean returnval = true;
//gameList[0]
Cursor cursor = db.query(TABLE_NAME, new String[] {VALUE}
,VALUE+" like " + "'%"+ userChoice +"%'", null, null, null, null);
if (cursor != null) // I always enter here even if the string is no country
returnval = false;
return returnval;
}
and whatever I insert, even if the query result should be false(meaning cursor == null)
Two more questions:
-
How can I see the database that I have build in the emulator?
-
Should I run it outside my app and then to append it to my app? Or in the first compilation, the user will suffer a little overhead (the first time they use this app)?
Well, first off, when you want to check if a query returned without results, rather than check if cursor == null, you want to have an if statement like
At least that’s how I’m doing it, and it seems to be working fine for me.
Additionally, for your emulator, the databases are stored inside the image file, not as separate files on your hard drive.