android - Pass list item id into a contextmenu Click method -


i have database , need change remove , add values , created such contextmenu have chance change , remove clicked item. need know id of list item , within contextmenu have ids of menu. i'm doing right thing or there easier way.

    public boolean oncontextitemselected(menuitem item) {         //iniciação da base de dados         final helperdb myhelper = new helperdb(this.getactivity());         sqlitedatabase db = myhelper.getwritabledatabase();          string[] projection = {contrato_db.cidadeentry._id, column_nome,         };         // how want results sorted in resulting cursor         string sortorder = column_nome + " asc ";          string[] columns = new string[] { "_id", "nome" };         final cursor c = db.rawquery("select * cidade ", null);         c.movetofirst();          final adapterview.adaptercontextmenuinfo info = (adapterview.adaptercontextmenuinfo) item.getmenuinfo();         switch (item.getitemid()) {              case r.id.update: // <-- custom menu item id here                  int id = item.getitemid();                 final alertdialog.builder alert = new alertdialog.builder(getactivity());                 final edittext input = new edittext(getactivity());                 toast.maketext(this.getactivity(),c.getstring(tmp),toast.length_long).show();                 alert.settitle("editar :" + c.getstring(tmp));                 alert.setview(input);                 alert.setpositivebutton("ok", new dialoginterface.onclicklistener() {                     public void onclick(dialoginterface dialog, int whichbutton) {                         string value = input.gettext().tostring().trim(); 

to database id can this

final adapterview.adaptercontextmenuinfo info = (adapterview.adaptercontextmenuinfo) item.getmenuinfo(); long id = info.id; 

Popular posts from this blog