Android Alert Box Wont Stay Open -
as title says alert box in app wont stay open. box nested within loop checked when button clicked. when loop goes alert box flashes on screen before disappearing straight away.
is there sort of timer can put on alert box keep open or have implemented box incorrectly?
button w/ loop , nested alert box
button button= (button) findviewbyid(r.id.cookbutton); button.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { finish(); //deducting 1 ingredient final cursor ingredients = adapter.getrecipesingredients(recipecode); final cursor missing = adapter.missingingredients(recipecode); if(missing.getcount() == 0) { toast.maketext(getapplicationcontext(), "haveeverything", toast.length_short).show(); ingredients.movetofirst(); string ingredient = ingredients.getstring(ingredients.getcolumnindex("ingredient_name")); int measurement = ingredients.getint(ingredients.getcolumnindex("measurement")); adapter.deductingredient(ingredient, measurement); } else { alertdialog.builder alertdialogbuilder = new alertdialog.builder( context); // set title alertdialogbuilder.settitle("uh oh!"); // set dialog message alertdialogbuilder .setmessage("opps looks yuor out of stuff, want add shopping list?") .setcancelable(false) .setpositivebutton("yes",new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog,int id) { final cursor missing2 = adapter.missingingredients(recipecode); while(missing2.movetonext()) { string n = missing2.getstring(missing2.getcolumnindex("ingredient_name")); toast.maketext(getapplicationcontext(), "adding missing shopping list: " + n, toast.length_short).show(); adapter.insertitem(n, 100, "grams"); } singlerecipedisaply.this.finish(); } }) .setnegativebutton("no",new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog,int id) { // if button clicked, close // dialog box , nothing dialog.cancel(); } }); // create alert dialog alertdialog alertdialog = alertdialogbuilder.create(); // show alertdialog.show(); } } });
why have added finish()
in onclick
, must causing issue , activity must closing, not alertdialog
.
@override public void onclick(view v) { finish(); ... ...
remove finish()
@ work.
Comments
Post a Comment