I am trying to make dialog preference in preferences, where user just click positive button to trigger some action. (Clear database? No | Yes)
public class MyDialogPreference extends DialogPreference {
public MyDialogPreference(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
@Override
protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
Log.d(MainActivity.TAG, "# onDialogClosed: " + positiveResult);
}
}
I dont actually want to persist anything, just trigger onSharedPreferenceChanged listener, so I can handle it in the activity. But I cant figure out how to trigger it
//SOLUTION
@Override
protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
if(positiveResult) {
persistBoolean(!getPersistedBoolean(true));
}
Log.d(MainActivity.TAG, "# onDialogClosed: " + positiveResult);
}