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

前端 未结 2 1457
情歌与酒
情歌与酒 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: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)});
    

提交回复
热议问题