Android - Listview delete item and Refresh

后端 未结 9 1870
耶瑟儿~
耶瑟儿~ 2020-12-06 02:16

I am trying to implement ListView with Delete functionality to delete item from the listview. I am successful to delete but failed to refresh the listview after deletetion o

9条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 03:14

    I think instead of calling the activity again, you should set the adapter to the listview on the alertBox delete option after getting the updated data from the database and putting into listitemDisplay list like this.

    alertDialog.setButton("Delete", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                    try
                    {
                        db.open();
                                 String[] whereArgs={String.valueOf(pkID)};
                        return db.delete(DATABASE_TABLE_4,"pk_pkID == ?",whereArgs); 
                        listitemDisplay = db.getItemFromDB();
                        adapter = new ListView_CustomAdapter(this, listitemDisplay);
                        lview.setAdapter(adapter);
                        db.close();
                    }
                    catch(Exception e)
                    {
    
                    }
            } }); 
    

    This will refresh the listView

提交回复
热议问题