Get value from SQLite and Cursor comparison problem
I access the SQLite database on device. And 开发者_如何学编程get some values from table
Cursor c = db.query(.....);
I try compare this values to other string values like that:
if(c.getString(0) == "value")
but this comparison returns false all time.
In debug, i see the values and c.getString(0)
is "value", but comparison returns false..
How can I compare these values?
I tried c.getString(0).toString()
too.
Try using:
if(c.getString(0).equals("value"))
realize that c.getString(0)
means that you are requesting the 0 column index on the record currently being pointed to by the Cursor object. if you are not using managedQuery, i suggest you call c.moveToFirst()
before attempting to pull data. then explicity request the column index you want with c.getString(c.getColumnIndex("nameofcolumn"));
. note, of course, that "nameofcolumn" must have been requested in the query.
You don't need to use toString()
after getting value like getString(0)
. You can just simply compare this using this statement:
if(cursor.getString(0).equals("value")){
}
精彩评论