java - How to delete a row from database by position -
i want delete row position. wrote doesn't work. it's deleting row id, not position. don't know how write query.
for example, table:
position | name 1 | aaaa 2 | bbbb 3 | cccc 4 | dddd now i'm deleting row number 3. want table this:
position | name 1 | aaaa 2 | bbbb 3 | dddd this delete method main activity class:
public void onclickbtndelete(view view) { sparsebooleanarray checkeditempositions = getlistview() .getcheckeditempositions(); int itemcount = getlistview().getcount(); int[] tab = new int[itemcount]; (int = itemcount - 1; >= 0; i--){ tab[i] = itemcount - i; if (checkeditempositions.get(i)) { adapter.remove(list.get(i)); db.deletemyplace(new myplacestable(tab[i])); } } this delete method databasehandler:
public void deletemyplace(myplacestable myplace) { sqlitedatabase db = this.getwritabledatabase(); db.delete(table_my_places, key_id + " = ?", new string[] { string.valueof(myplace.getid()) }); db.close(); } and constructor, getter , setter:
public myplacestable(int id){ this._id = id; } public int getid(){ homecoming this._id; } public void setid(int id){ this._id = id; } can help me?
try
public static void deletedata(sqlitedatabase db, string tablename,string userfield,string userid) { string table_name = tablename; string =userfield + "='" +userid+"'"; string whereargs[] = null; db.delete(table_name, where, whereargs); } java android sql database delete-row
No comments:
Post a Comment