I have to admit, I don't know cursors that well, so I'm learning a bit
here. I really think it has something to do with the call to
startManagingCursor(myTeaCursor) that you make. I have gotten to where
I get a SQLLiteException due I guess to some query not working.

I've tried experimenting with some things in the TeaTime activity, so
maybe you can try these as well:

- Override onActivityResult and make a call to fillData()
- Make a call to stopManagingCursor(myTeaCursor) in an overridden
onFreeze()


On Mar 23, 4:25 pm, MobileBen <[EMAIL PROTECTED]> wrote:
> Here it is. Thank you again for your help. I appreciate that. I still
> didn't find the solution :(
>
> public class TeaDB {
>
>     public static final String KEY_NAME="name";
>     public static final String KEY_BREWTIME="brewTime";
>     public static final String KEY_ROWID="_id";
>
>     /**
>      * Database creation sql statement
>      */
>     private static final String DATABASE_CREATE =
>         "CREATE TABLE IF NOT EXISTS "+
>                 "TeaTable" +
>                 " (_id integer primary key autoincrement, name text not null,
> brewTime integer not null);";
>
>     private static final String DATABASE_NAME = "TeaTimeDatabase";
>     private static final String DATABASE_TABLE = "TeaTable";
>     private static final int DATABASE_VERSION = 2;
>
>     private SQLiteDatabase myDb = null;
>     private final Context mCtx;
>
>     /**
>      * Constructor - takes the context to allow the database to be
> opened/created
>      * @param ctx the Context within which to work
>      */
>     public TeaDB(Context ctx) {
>         this.mCtx = ctx;
>     }
>
>     /**
>      * Open the teaTable database. If it cannot be opened, try to
> create a new instance of
>      * the database. If it cannot be created, throw an exception to
> signal the failure
>      * @return this (self reference, allowing this to be chained in an
> initialization call)
>      * @throws SQLException if the database could be neither opened or
> created
>      */
>     public TeaDB open() throws SQLException {
>            try {
>             myDb = mCtx.openDatabase(DATABASE_NAME, null);
>         } catch (FileNotFoundException e) {
>
>             try {
>                myDb =  mCtx.createDatabase(DATABASE_NAME,
> DATABASE_VERSION, 0,
>                         null);
>
>                myDb.execSQL(DATABASE_CREATE);
>     /*            myDb.execSQL("CREATE TABLE "
>                                         + DATABASE_TABLE
>                                         + " (Name TEXT, brewTime INT(3));");*/
>
>             } catch (FileNotFoundException ex1) {
>                 throw new SQLException("Could not create database");
>             }
>     }
>         return this;
>     }
>
>     public void close() {
>         myDb.close();
>     }
>
>     /**
>      * Create a new Tea using the name and brewTime provided. If the
> Tea is successfully created
>      * return the new rowId for that Tea, otherwise return a -1 to
> indicate failure.
>      * @param name the name of the Tea
>      * @param brewTime the brewTime of the Tea
>      * @return rowId or -1 if failed
>      */
>     public long createTea(String name, int brewTime) {
>         ContentValues initialValues = new ContentValues();
>         initialValues.put(KEY_NAME, name);
>         initialValues.put(KEY_BREWTIME, brewTime);
>         return myDb.insert(DATABASE_TABLE, null, initialValues);
>     }
>
>     /**
>      * Delete the Tea with the given rowId
>      * @param rowId id of Tea to delete
>      * @return true if deleted, false otherwise
>      */
>     public boolean deleteTea(int brewTime) {
>         return myDb.delete(DATABASE_TABLE, "brewTime" + "=" +
> brewTime, null) > 0;
>     }
>
>     /**
>      * Return a Cursor over the list of all Teas in the database
>      * @return Cursor over all Teas
>      */
>     public Cursor callUpAllTeas() {
>         return myDb.query(DATABASE_TABLE, new String[] {
>                 KEY_ROWID, KEY_NAME, KEY_BREWTIME}, null, null, null,
> null, null);
>     }
>
>     /**
>      * Return a Cursor positioned at the Tea that matches the given
> rowId
>      * @param rowId id of Tea to retrieve
>      * @return Cursor positioned to matching Tea, if found
>      * @throws SQLException if Tea could not be found/retrieved
>      */
>     public Cursor catchUpTea(long rowId) throws SQLException {
>         Cursor result = myDb.query(true, DATABASE_TABLE, new String[]
> {
>                 KEY_ROWID, KEY_NAME, KEY_BREWTIME}, KEY_ROWID + "=" +
> rowId, null, null,
>                 null, null);
>         if ((result.count() == 0) || !result.first()) {
>             throw new SQLException("No Tea matching ID: " + rowId);
>         }
>         return result;
>     }
>
>     /**
>      * Update the Tea using the details provided. The Tea to be
> updated is specified using
>      * the rowId, and it is altered to use the Name and BrewTime
> values passed in
>      * @param rowId id of note to update
>      * @param name value to set Tea name to
>      * @param brewTime value to set Tea brewTime to
>      * @return true if the Tea was successfully updated, false
> otherwise
>      */
>     public boolean updateTea(long rowId, String name, int brewTime) {
>         ContentValues args = new ContentValues();
>         args.put(KEY_NAME, name);
>         args.put(KEY_BREWTIME, brewTime);
>         return myDb.update(DATABASE_TABLE, args, KEY_ROWID + "=" +
> rowId, null) > 0;
>     }
>
> }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to