编辑文字首选项

时间:2011-12-13 11:57:11

标签: android android-edittext android-preferences

我已经进行了编辑首选项,但是当我使用onchangelistener侦听器时,我没有得到ondismiss,但是当我使用onchange侦听器注释时,但是在取消注释之后我没有得到onchangelistener

public class Preferences extends PreferenceActivity{
    SharedPreferences sharedPreferences=null;
    String text=null;
    String negativeBtnTxt=null;
    private EditTextPreference editTextPreference=null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        addPreferencesFromResource(R.xml.preference_layout);
        sharedPreferences=PreferenceManager.getDefaultSharedPreferences(getBaseContext());

        Preference preference=(Preference)findPreference("customPref");

        editTextPreference=(EditTextPreference)findPreference("editTextPref");  
        editTextPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                Log.v("in Preferences","edit text pref onclick");
                dialogActivated();
                return false;
            }
        });


        editTextPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {     
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                Log.v("in Preferences","edit text pref changed");
                return false;
            }
        });

        Log.v("edit text dialog=","---"+editTextPreference.getDialog());

        Log.v("ET value is=",""+sharedPreferences.getString("editTextPref", "Hello!!!"));

        preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                Toast.makeText(getApplicationContext(), "Clicked on preference", 3).show();

                Log.v("in Preferences","");
                return false;
            }
        });
    }

    private void dialogActivated()
    {
        if(editTextPreference.getDialog()!=null)
        {

            editTextPreference.getDialog().setCancelable(true);
            editTextPreference.getDialog().setOnCancelListener(new OnCancelListener() {

                @Override
                public void onCancel(DialogInterface dialog) {

                    Log.v("in Preferences","back key cancel");
                }
            });

            editTextPreference.getDialog().setOnDismissListener(new OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialog) {
                    Log.v("in Preferences","dismis called");
                    editTextPreference.getNegativeButtonText();
                }
            });
        }
    }
}

0 个答案:

没有答案