views:

54

answers:

2

Hi, i'm working on a android app that will display Strings to the user, and the user then has the option to add one to a favorite list. I have searched and searched and cannot find the proper way of doing this. I did get one open source project, everything worked until the user removed a favorite. The database would clear the row of data, but when a new row is added, it would behave as if the deleted row still had data, leaving blanks in the favorite list.

this is my insert method

  public long insertString(String newString) 
  {
    ContentValues newStringValue = new ContentValues();

    newStringValue.put(KEY_STRING, newString);

    return db.insert(DATABASE_TABLE, null, newStringValue);
  }

the long returned will always increment even if i use the remove method:

 public boolean removeString(long _rowIndex)
  {
    return db.delete(DATABASE_TABLE, KEY_ID + "=" + _rowIndex, null) > 0;
  }

if i try to remove the third index, and the user removed a question at the third index, the method returns false, is there a way to completely remove all rows with no data?

A: 

Maybe just encode String List as something like JSON, then save as long string (blob / clob)? I would use Jackson JSON processor, but there are many alternatives to choose from (Guice, or XStream if you prefer XML). I mean, assuming you don't really need relational aspects of data (no need to find users with specific list entry by querying) but just need to persist lists.

StaxMan
A: 

You should use a CursorAdapter or ResourceCursorAdapter and when you modify the data call cursor.requery() to refresh everything.

Al Sutton
thanks, that worked out for me