Android Add Yes/No box to listView.setOnItemClickListener -
i've been trying lot of things try working, have list view displaying sqlitedb. each row of database clickable want able copy table in database. function working fine. problem want yes/no box appear confirm before gets copied in. have gone through numerous tutorials , been on here searching solution, none can fit in. here code have sitting inside displaylistview() method. in advance!
listview.setonitemclicklistener(new onitemclicklistener() { public void onitemclick(adapterview<?> listview, view view, int position, long id) { // cursor, positioned corresponding row in // result set cursor cursor = (cursor) listview.getitematposition(position); dbhelper.addtoplanner( cursor.getstring(cursor.getcolumnindexorthrow("band")), cursor.getstring(cursor.getcolumnindexorthrow("day")), cursor.getstring(cursor.getcolumnindexorthrow("stage")), cursor.getdouble(cursor.getcolumnindexorthrow("stime")), cursor.getdouble(cursor.getcolumnindexorthrow("ftime")), cursor.getstring(cursor.getcolumnindexorthrow("planner"))); string displayme = cursor.getstring(cursor.getcolumnindexorthrow("band")); toast.maketext(getapplicationcontext(), displayme, toast.length_short).show(); } });
after taking break few minutes of course figured out!! had divide dialog box declaration , method , declare things here , there. here's how got working, hope helps else out.
final alertdialog.builder builder = new alertdialog.builder(this); listview.setonitemclicklistener(new onitemclicklistener() { public void onitemclick(adapterview<?> listview, view view, int position, long id) { // cursor, positioned corresponding row in result set cursor cursor = (cursor) listview.getitematposition(position); final string band = cursor.getstring(cursor.getcolumnindexorthrow("band")); final string day = cursor.getstring(cursor.getcolumnindexorthrow("day")); final string stage = cursor.getstring(cursor.getcolumnindexorthrow("stage")); final double stime = cursor.getdouble(cursor.getcolumnindexorthrow("stime")); final double ftime = cursor.getdouble(cursor.getcolumnindexorthrow("ftime")); final string planner = cursor.getstring(cursor.getcolumnindexorthrow("planner")); builder.settitle("add planner") .setmessage("add planner") .seticon(android.r.drawable.ic_dialog_alert); builder.setpositivebutton("yes",new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { // todo auto-generated method stub dbhelper.addtoplanner(band, day, stage, stime, ftime, planner); } }).setnegativebutton("no", null).show(); string countrycode = cursor.getstring(cursor.getcolumnindexorthrow("band")); toast.maketext(getapplicationcontext(), countrycode, toast.length_short).show(); } });
i recommend creating alert dialg. here link help: http://www.mkyong.com/android/android-alert-dialog-example/
Comments
Post a Comment