samedi 12 décembre 2015

How do I delete a row in listview by long-click and also SQLite

I want to long click on a listview (which the data is also from the SQLite) and then a delete pop-up menu showed up. When I click on the delete pop-up menu, the selected row in the listview will be deleted and together with the database.

view_lv_diary_info.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            PopupMenu p = new PopupMenu(ViewDiaryActivity.this, view);
            p.getMenuInflater().inflate(R.menu.main_popup_menu, p.getMenu());
            p.show();

            return true;
        }           
    });

onDelete method:

public void doDelete(MenuItem mi) {

    /* db.delete(DiaryEntry.TABLE_NAME,
            ??,
            ??);
    */
    Toast.makeText(this, "Record deleted.", Toast.LENGTH_SHORT).show();
}

I've tried this code and the toast showed up. But I don't know the SQL statement.

Thanks :)

Aucun commentaire:

Enregistrer un commentaire