使用onPreferenceClick创建AlertDialog

时间:2013-04-12 20:44:30

标签: android

我正在尝试使用此代码单击首选项时打开AlertDialog:

public class Opciones extends PreferenceActivity {

    private Context ctx;

    @SuppressWarnings("deprecation")
    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.opciones);

        Preference myPref = (Preference) findPreference("sobreApp");
        myPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            public boolean onPreferenceClick(Preference preference) {
                AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
                builder.setCancelable(true);
                builder.setTitle(R.string.sobreApp);
                builder.setMessage(R.string.sobrePokeDroidex);
                builder.show();
                return false;
            }
        });

    }

}

但是当我点击prefence应用程序关闭时。有什么建议吗?

0 个答案:

没有答案