我OnPreferenceClickListener
创建了一个新的AlertDialog
,如下所示。当我运行程序时,我得到了期望
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
我的代码有什么问题?
public static class PrefsFragment extends PreferenceFragment {
Preference pref= findPreference("text_preference1");
pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
new AlertDialog.Builder(mContext).setTitle(R.string.alert_dialog_title)
.setMessage(R.string.alert_dialog_message)
.setPositiveButton(R.string.alert_dialog_ok,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setNegativeButton(R.string.alert_dialog_nein, null).show();
//do s.th.
return false;
}
});
}