How Can I Access My Activity's Instance Variables From Within An Alertdialog's Onclicklistener?
Here's a very simplified version of my Activity: public class Search extends Activity { //I need to access this. public SearchResultsAdapter objAdapter; public boolea
Solution 1:
Using Search.this.objAdapter
to access objAdapter
from the listener should work.
Search.this
refers to the current instance of Search
and allow you to access its fields and methods.
Solution 2:
Make your activity implement OnClickListener:
publicclassSearchextendsActivityimplementsDialogInterface.OnClickListener { ...
Add the onclick method to your activity:
publicvoidonClick(DialogInterface dialog, int item){
//I need to access it from here.
}
Then pass your activity as the listener:
AlertDialog.Builderbuilder=newAlertDialog.Builder(this);
builder.setTitle(itmMenuitem.getTitle());
builder.setSingleChoiceItems(lstChoices),0, this);
Post a Comment for "How Can I Access My Activity's Instance Variables From Within An Alertdialog's Onclicklistener?"