Reputation: 17
I created a PreferenceActivity with a Custom Title. In the title I added a button. In the button click event I added:
imageClearCache.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
....
new AlertDialog.Builder(getApplicationContext())
.setTitle("Alert!!")
.setMessage("Text...")
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// continue with delete
}
}).show();
}
I get the error: ...Unable to add window -- token null is not for an application
Any idea?
Best regards
Upvotes: 0
Views: 1079
Reputation: 17140
Use the normal context (in this case your activity) provided by the view being clicked instead of the application context.
new AlertDialog.Builder(v.getContext())
Upvotes: 1