java - issue with alert dialog box, due to it not recognizing the initiation of the alert box -
i trying create dialog box show when image clicked there seems few issues code. code shown below. have done import dialog box doesn't seem work there error when initiating new dialog box.
imagebutton ib = (imagebutton)findviewbyid(r.id.imagebutton1); ib.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { alertdialog ad = new alertdialog.builder(this) .setmessage("blah blah blah.\n fine pring.\n accept our terms , conditions?") .seticon(r.drawable.ic_launcher) .settitle("terms of service") .setneutralbutton("back", this) .setcancelable(false) .create(); ad.show(); } });
the problem reference this
on line
alertdialog ad = new alertdialog.builder(this)
is referring anonymous inner class view.onclicklistener
not extend context. so, above your
ib.setonclicklistener(new view.onclicklistener() {
put effect of
final context context = this;
and change aforemention builder call read
alertdialog ad = new alertdialog.builder(context)
i.e.
imagebutton ib = (imagebutton)findviewbyid(r.id.imagebutton1); final context context = this; ib.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { alertdialog ad = new alertdialog.builder(context) .setmessage("blah blah blah.\n fine pring.\n accept our terms , conditions?") .seticon(r.drawable.ic_launcher) .settitle("terms of service") .setneutralbutton("back", this) .setcancelable(false) .create(); ad.show(); } });
and making (perhaps lofty) assumption that block of code indeed reside within class in fact extend context.
Comments
Post a Comment