Android AlertDialog clicking Positive and Negative just dismiss
- by timmyg13
Trying to have a sharedpreference where you click on it to restore default values, then an alert dialog comes up to ask if you are sure, but it is not doing anything, just dismissing the alertdialog.
public class SettingsActivity extends PreferenceActivity implements
OnSharedPreferenceChangeListener {
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
c = this;
addPreferencesFromResource(R.xml.settings);
SharedPreferences sp = PreferenceManager
.getDefaultSharedPreferences(this);
sp.registerOnSharedPreferenceChangeListener(this);
datasource = new PhoneNumberDataSource(this);
Preference restore = (Preference) findPreference("RESTORE");
restore.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
createDialog();
return false;
}
});
}
void createDialog() {
Log.v("createDialog", "");
FrameLayout fl = new FrameLayout(c);
AlertDialog.Builder b = new AlertDialog.Builder(c).setView(fl);
b.setTitle("Restore Defaults?");
b.setPositiveButton("Restore",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d,
int which) {
Log.v("restore clicked:", "");
}
});
b.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d,
int which) {
Log.v("cancel clicked:", "");
d.dismiss();
}
}).create();
b.show();
}
}
Neither the "cancel clicked" nor "restore clicked" show in the log. I do get a weird "W/InputManagerService(64): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@450317b8" in the log.