android - Deleting data from SQLite using listview by clicking Delete Button -


okay, supervisor wants me this:

  • the third screen should accessible via "view all" button. should show records added. beside each name, there should delete button removing record sqlite database.

please refer link see i'm talking since i'm not in expressing myself in english.

screen shot http://i50.tinypic.com/dm9zqg.jpg

i've made way show data saved in database, have no idea on how automatically put delete button beside data , delete clicking it.

here's code: (if there more simple codes can suggest, i'll more glad.)

public class checkdata extends listactivity implements onclicklistener  {          textview selection;     public int idtomodify;      datamanipulator dm;      list<string[]> list = new arraylist<string[]>();     list<string[]> names2 =null ;     string[] stg1;     protected void oncreate(bundle savedinstancestate){     super.oncreate(savedinstancestate);     setcontentview(r.layout.check);     dm = new datamanipulator(this);     names2 = dm.selectall();     stg1=new string[names2.size()];      int x=0;     string stg;     (string[] name : names2) {         stg = name[1];         stg1[x]=stg;         x++; //onclick         view homeonviewall = findviewbyid(r.id.homeonviewall);         homeonviewall.setonclicklistener(this);         view newdataonviewall = findviewbyid(r.id.newdataonviewall);         newdataonviewall.setonclicklistener(this);           }     arrayadapter<string> adapter = new arrayadapter<string>(this,android.r.layout.simple_list_item_1,stg1);         this.setlistadapter(adapter);     selection=(textview)findviewbyid(r.id.selection);    }       @override     public void onclick(view v) {                 // todo auto-generated method stub         switch(v.getid()){             case r.id.homeonviewall:                     intent = new intent(this, dbsample.class);                       startactivity(a);                     break;                     case r.id.newdataonviewall:                     intent b = new intent(this, savedata.class);                       startactivity(b);                     break;                          }             }   } 

1) make layout display name , delete button. pass layout adapter, use android.r.layout.simple_list_item_1, example

new arrayadapter<string>(this, r.layout.row_layout_delete, stg1); 

2) extend adapter , override getview() add onclicklistener button. inside onclick() delete current row.

i recommend using cursoradapter, simplecursoradapter, designed link database information listview.


this answer covers topic, provide details on how extend adapter , implement onclicklistener: how attach multiple touch actions single list item?, "quick , dirty" answer should you. should watch google i/o presentation turbo-charge ui adapters.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -