0

尝试有一个共享首选项,单击它以恢复默认值,然后出现一个警报对话框询问您是否确定,但它没有做任何事情,只是关闭警报对话框。

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"在日志中得到了一个奇怪的东西。

4

0 回答 0