Skip to content Skip to sidebar Skip to footer

Delete A Specific Item From Listview Stored In Database In Android Application

I am making an android application in which i have five items in a list .On each item click data is coming from url and then i have stored the items in local database.Now i want to

Solution 1:

you need to remove the item from the position and then set the adapter again so that the list will be refreshed.

listofitems.remove(tempPosition);

setListAdapter(customAdapter );

to remove from the database. use the position to get the id.

c.moveToPosition(position);
         id= c.getInt(c.getColumnIndex("_id"));

using the id you can delete

myDataBase.delete(tablename, "_id=?", new String[] {Integer.toString(id)});

Solution 2:

you can set onclick listener for the items in the adapter and in that onclick you can delete the textview and using the above method can delete it from the database.

check this question and answer.

Deleting items from a ListView using a custom BaseAdapter

you can combine this and come to a solution. sorry i havent done something like you are doing. this is an idea.


Post a Comment for "Delete A Specific Item From Listview Stored In Database In Android Application"