android - Delete specific row with ContextMenu sqlite -


i have listview who's populated data inserted in sqlite database.

i created contextmenu can able delete items listview.

when click on delete, want delete item database , listview. i'm not able , don't know why. want delete getting string of item i, because not work primary key.

here's code :

databasehelper

 public void deletecours(string cours) {     open();     db.execsql("delete "+table_cours+" "+colonne_cours+"='"+cours+"'");     db.close(); } 

my listview , contextmenu

        //ce listener permet de détecter si on clique sur un élément de la liste     lv.setonitemclicklistener(new adapterview.onitemclicklistener()     {          @override         public void onitemclick(adapterview<?> adapterview, view view, int i, long l) {              //récupération de l'id             long itemid= lv.getitemidatposition(i);             //conversion en int             int id= (int)itemid;             //conversion en string du cours que je selectionne             string =lv.getitematposition(i).tostring();             dbhelper.deletecours(a);             //intent pour naviguer de pag             /*intent b = new intent(affichagecours.this,affichagenotes.class);             //création d0un bundle pour transférer des données             bundle args = new bundle();             args.putstring("nom_cours",a);             args.putint("id",id);             //insertion du bundle dans l'intent             b.putextras(args);             //démarrage de l'intent             startactivity(b);*/         }      }); }  @override public void oncreatecontextmenu(contextmenu menu, view v, contextmenu.contextmenuinfo menuinfo) {     super.oncreatecontextmenu(menu, v, menuinfo);     menuinflater inflater = getmenuinflater();     inflater.inflate(r.menu.context_menu,menu);  }  @override public boolean oncontextitemselected(menuitem item) {     adapterview.adaptercontextmenuinfo info = (adapterview.adaptercontextmenuinfo) item.getmenuinfo();      switch(item.getitemid())     {         case r.id.supprimer:              // want delete here !             return true;         default:             return super.oncontextitemselected(item);     } } 

}

so, i need string of item can use in method. ii want refresh listview automatically.

thank's in advance ! tell me if need more code !

try way

public void deletecours(int id) {     open();     db.execsql("delete "+table_cours+" "+colonne_idcours+"='"+id+"'");     db.close(); } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -