delete a specific item from listview stored in database in android application

前端 未结 2 1458
情歌与酒
情歌与酒 2021-01-27 04:07

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

相关标签:
2条回答
  • 2021-01-27 04:20

    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.

    0 讨论(0)
  • 2021-01-27 04:36

    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)});
    
    0 讨论(0)
提交回复
热议问题