My database creates and populates without any problems. I even have a custom adapter to display the rows in listviews in my activity.
The problem is my _id column doesn’t actually have any ids.
I have a dialogue box come up on listItemClick with the data being put into text boxes, there are buttons at the bottom, I’m trying to get the ‘delete’ button to work so the user can delete that record. I’m trying to delete the record calling the _id however the ID column of my database is empty for all my records. The dialogue box displays the ID number for each item and they come up as 0 for all of them and when I open the database with sqlite database browser the id column is completely empty for every record. Can anyone please help and tell me why this is?
This is the tutorial I used:
http://android-er.blogspot.co.uk/2011/06/edit-row-in-sqlite-database-using.html
Some code:
Creating database and table:
public static final String KEY_ID = "_id";
public static final String KEY_LESSON = "Lesson";
public static final String KEY_DAY = "Day";
public static final String KEY_START = "Start";
public static final String KEY_END = "End";
public static final String KEY_LOCATION = "Location";
private SQLiteDatabase db;
private DBHelper dbHelper;
private final Context context;
private static final String DATABASE_CREATE = "create table Schedule" + " (" + KEY_ID + " INTERGER PRIMARY KEY,"
+ KEY_LESSON + " text not null, " + KEY_DAY + " text not null," + KEY_START + " text not null, " + KEY_END
public void deleteEntry(int id) {
db.delete(DATABASE_TABLE, KEY_ID + "=" +id, null);
}
Dialogue:
myDialog.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
db.open();
db.deleteEntry(item_id);
}
});
This is wrong:
This would be better: