androidsqlitelistactivitysimplecursoradapter

Column '_id' does not exist SimpleCursorAdapter revisited


I want to use the SimpleCursorAdapter to fill in my ListActivity, but I'm getting the classic exception because there is no '_id' field in my Cursor. Unfortunately, this type of query does not provide me with a field that I can use as my _id field being of the form:

SELECT DISTINCT room from tblRates WHERE resid='ABC' AND date='2011-10-17'

Because of the DISTINCT I can't just add in the _id. So what do I do short of setting up a custom Adapter?

Btw, I have seen this post already so I do understand why I'm getting the error. Just wondering how to get an _id in there with the type of query I'm doing:

Android column '_id' does not exist?


Solution

  • You could do something like this...

    SELECT DISTINCT room, 1 _id from tblRates WHERE resid='ABC' AND date='2011-10-17'
    

    This will add an _id column with a value of 1 for each row. Also I think sqlite has something like a hidden "rowid" column for each table if you want distinct values for the column instead of a 1.