Getting the context inside onClick(View view), the callback for a button\'s onClickListener(), is easy:
view.getContext()
>
Here is how you do it in case you
Just simply,
dialogInterface object and cast it to Dialog objectgetContext()Example with DialogInterface.OnClickListener:
DialogInterface.OnClickListener foo = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {
Dialog dialog = (Dialog) dialogInterface;
Context context = dialog.getContext();
// do some work with context
}
};
This will also work for the following interfaces as well, just use the first param DialogInterface dialogInterface and cast.