how to call the ok button in the EditTextPreference

后端 未结 3 437
离开以前
离开以前 2020-12-07 04:05

I have an EditTextPreference in the PreferenceActivity. When user click the EditTextPreference will show a dialog. In the dialog, us

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-07 04:31

    You can extend EditTextPreference to get control over the click handler.

    package myPackage;
    public class CustomEditTextPreference extends EditTextPreference {
    
        public CustomEditTextPreference(Context context) {
            super(context);
        }
    
        public CustomEditTextPreference(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public CustomEditTextPreference(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }
    
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == DialogInterface.BUTTON_POSITIVE) {
                // add Handler here
            }
            super.onClick(dialog, which);
        }
    
    }
    

    In the Xml instead of reference it like this:

    
    

提交回复
热议问题