Can't Get An Alertdialog To Work
I have an onLongClickListener that resets some values when called. I would like to ad an alertDialog to check if the user really does want to reset all the values. However I am hav
Solution 1:
The problem is that this line of code:
AlertDialog.Builderalertbox=newAlertDialog.Builder(this);
is actually inside of anonymous inner class which implements the interface OnLongClickListener
. The argument to the AlertDialog.Builder() constructor must be a Context object. this
as an argument here, refers to the anonymous inner class object, which does not extend Context. I'm guessing that your posted code fragment is inside an Activity object, in which case, change the line to:
AlertDialog.Builderalertbox=newAlertDialog.Builder(OuterClass.this);
where OuterClass is the name of your Activity class that this method is inside. This is the syntax used to refer to the object that an inner class is defined in.
Solution 2:
AlertDialog.Builderalertbox=newAlertDialog.Builder(v.getContext());
Post a Comment for "Can't Get An Alertdialog To Work"