尝试在共享首选项的位置单击它以恢复默认值,然后会出现一个警告对话框询问您是否确定,但它没有执行任何操作,只是解除了警告对话框。
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();
}
}
日志中未显示“取消点击”或“恢复点击”。我在日志中得到了一个奇怪的"W/InputManagerService(64): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@450317b8"
。