首次点击editext中的日历图标未显示datepicker对话框

时间:2017-07-13 17:57:03

标签: android

Hai我在我的应用程序中有editext,我们可以设置出生日期。在那个editext我有一个日历图标。如果我们点击日历图标,它应该打开datepicker对话框。但在我的情况下,如果我点击日历图标,它会在我的editext中显示粘贴,clicpboard,selectall选项,而不是显示日期选择器对话框,如果我们第二次再次点击日历图标,则会打开日期选择器对话框。如何在第一次单击我的日历图标时打开datepicker对话框。我将setFocusable和setFocusableInTouchMode设置为false但没有用。请帮助修复相同的问题。

这是我有出生日期编辑文本的片段:

public class RegistrationBasicInformationFragment extends Fragment implements
        IRegistrationBasicInformationView, IRegistrationItemEventListener, View.OnFocusChangeListener {

    private TextView mRegistrationEnterYourBasicInformationLabel;
    private RelativeLayout mRegistrationBasicInformationMainLayout;
    private DsmApplication mDsmApplication;

    private RegistrationItemView mRegistrationBasicInformationItemForFirstName;
    private RegistrationItemView mRegistrationBasicInformationItemForLastName;
    private RegistrationItemView mRegistrationBasicInformationItemForDob;
    private RegistrationItemView mRegistrationBasicInformationItemForEmail;
    private RegistrationItemView mRegistrationBasicInformationItemForGender;
    private RegistrationItemView mRegistrationBasicInformationItemForNickName;
    private RegistrationItemView mRegistrationBasicInformationItemForPhoneNumber;
    private RegistrationItemView mRegistrationBasicInformationItemForPractice;
    private RegistrationItemView mRegistrationBasicInformationItemForProvider;
    private RegistrationBasicInformationController mRegistrationBasicInformationController;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.registration_basicinformation_view_v222, container, false);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mDsmApplication = (DsmApplication) getActivity().getApplication();
        loadController();
        loadView(view);
    }

    private void loadController() {
        mRegistrationBasicInformationController = new RegistrationBasicInformationController(this);
        mDsmApplication.registerController(RegistrationBasicInformationController.TAG, mRegistrationBasicInformationController);
    }

    private void loadView(View view) {
        mRegistrationBasicInformationMainLayout = (RelativeLayout) view
                .findViewById(R.id.registration_basicinformation_relativelayout_for_itself);

        mRegistrationEnterYourBasicInformationLabel = (TextView) view
                .findViewById(R.id.registration_basicinformation_textview_for_headerlabel);

        mRegistrationBasicInformationItemForFirstName = (RegistrationItemView) view
                .findViewById(R.id.registration_basicinformation_registrationitemview_for_firstname);
        mRegistrationBasicInformationItemForFirstName.mRegistrationItemTextTypeEditText.setOnFocusChangeListener(this);
        mRegistrationBasicInformationItemForLastName = (RegistrationItemView) view
                .findViewById(R.id.registration_basicinformation_registrationitemview_for_lastname);
        mRegistrationBasicInformationItemForLastName.mRegistrationItemTextTypeEditText.setOnFocusChangeListener(this);

        mRegistrationBasicInformationItemForDob = (RegistrationItemView) view
                .findViewById(R.id.registration_basicinformation_registrationitemview_for_dob);

        mRegistrationBasicInformationItemForGender = (RegistrationItemView) view
                .findViewById(R.id.registration_basicinformation_registrationitemview_for_gender);

        mRegistrationBasicInformationItemForPhoneNumber = (RegistrationItemView) view
                .findViewById(R.id.registration_basicinformation_registrationitemview_for_phonenumber);
        mRegistrationBasicInformationItemForPhoneNumber.mRegistrationItemTextTypeEditText.setOnFocusChangeListener(this);

        mRegistrationBasicInformationItemForNickName = (RegistrationItemView) view
                .findViewById(R.id.registration_basicinformation_registrationitemview_for_nickname);
        mRegistrationBasicInformationItemForNickName.mRegistrationItemTextTypeEditText
                .setOnFocusChangeListener(this);
        mRegistrationBasicInformationItemForNickName.mRegistrationItemTextTypeEditText
                .setOnEditorActionListener(new TextView.OnEditorActionListener() {
                    @Override
                    public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                        if (i == EditorInfo.IME_ACTION_NEXT) {
                            if (mRegistrationBasicInformationItemForDob.isEnabled() ) {
                                mRegistrationBasicInformationController.OnCalendarDateTimeIconClicked();
                                ViewUtils.hideVirturalKeyboard((EditText) textView);
                            } else {
                                mRegistrationBasicInformationItemForPhoneNumber.mRegistrationItemTextTypeEditText.requestFocus();
                                ViewUtils.showVirturalKeyboard(getActivity().getApplicationContext());
                            }
                            return true;
                        }
                        return false;
                    }
                });

        mRegistrationBasicInformationItemForEmail = (RegistrationItemView) view
                .findViewById(R.id.registration_basicinformation_registrationitemview_for_email);
        mRegistrationBasicInformationItemForEmail.mRegistrationItemTextTypeEditText.setOnFocusChangeListener(this);

        mRegistrationBasicInformationItemForPractice = (RegistrationItemView) view
                .findViewById(R.id.registration_basicinformation_registrationitemview_for_practice);
        mRegistrationBasicInformationItemForProvider = (RegistrationItemView) view
                .findViewById(R.id.registration_basicinformation_registrationitemview_for_provider);
    }

    @Override
    public void SetEnterYourBasicInformationLabel(String label) {
        mRegistrationEnterYourBasicInformationLabel.setText(label);
    }

    @Override
    public IRegistrationItemView CreateFirstNameItemView(String label, int type, String value,
                                                         int validationId) {
        mRegistrationBasicInformationItemForFirstName.SetEventListener(this);
        mRegistrationBasicInformationItemForFirstName.SetLabel(label);
        mRegistrationBasicInformationItemForFirstName.SetValue(value);
        mRegistrationBasicInformationItemForFirstName.SetValidationId(validationId,
                IRegistrationItemView.VALUETYPE_TEXTFIELD);
        return mRegistrationBasicInformationItemForFirstName;
    }

    @Override
    public IRegistrationItemView CreateLastNameItemView(String label, int type, String value,
                                                        int validationId) {
        mRegistrationBasicInformationItemForLastName.SetEventListener(this);
        mRegistrationBasicInformationItemForLastName.SetLabel(label);
        mRegistrationBasicInformationItemForLastName.SetValue(value);
        mRegistrationBasicInformationItemForLastName.SetValidationId(validationId, IRegistrationItemView.VALUETYPE_TEXTFIELD);
        return mRegistrationBasicInformationItemForLastName;
    }

    @Override
    public IRegistrationItemView CreateNickNameItemView(String label, int type, String value, int validationId) {
        mRegistrationBasicInformationItemForNickName.SetEventListener(this);
        mRegistrationBasicInformationItemForNickName.SetLabel(label);
        mRegistrationBasicInformationItemForNickName.SetValue(value);
        mRegistrationBasicInformationItemForNickName.SetValidationId(validationId, IRegistrationItemView.VALUETYPE_TEXTFIELD);
        return mRegistrationBasicInformationItemForNickName;
    }

    @Override
    public IRegistrationItemView CreatePracticeItemView(String label, int type, IStringList
            valuesList, String defaultValue, int validationId) {
        mRegistrationBasicInformationItemForPractice.SetEventListener(this);
        mRegistrationBasicInformationItemForPractice.SetLabel(label);
        mRegistrationBasicInformationItemForPractice.SetValueList(type, valuesList);
        mRegistrationBasicInformationItemForPractice.SetValidationId(validationId,
                IRegistrationItemView.VALUETYPE_LIST);
        return mRegistrationBasicInformationItemForPractice;
    }

    @Override
    public IRegistrationItemView CreateProviderItemView(String label, int type, IStringList
            valuesList, String defaultValue, int validationId) {
        mRegistrationBasicInformationItemForProvider.SetEventListener(this);
        mRegistrationBasicInformationItemForProvider.SetLabel(label);
        mRegistrationBasicInformationItemForProvider.SetValueList(type, valuesList);
        mRegistrationBasicInformationItemForProvider.SetValidationId(validationId,
                IRegistrationItemView.VALUETYPE_LIST);
        return mRegistrationBasicInformationItemForProvider;
    }

    @Override
    public void ShowPracticeItemView() {
        mRegistrationBasicInformationItemForPractice.setVisibility(View.VISIBLE);
    }

    @Override
    public void ShowProviderItemView() {
        mRegistrationBasicInformationItemForProvider.setVisibility(View.VISIBLE);
    }

    @Override
    public void RefreshScreen() {
        // NA
    }

    @Override
    public void SetGender(int isMale) {
        mRegistrationBasicInformationItemForGender.SetValueForSwitch(isMale);
    }

    @Override
    public IRegistrationItemView CreateDobItemView(String label, int type, String value,
                                                   int validationId) {
        mRegistrationBasicInformationItemForDob.SetEventListener(this);
        mRegistrationBasicInformationItemForDob.SetLabel(label);
        mRegistrationBasicInformationItemForDob.SetValidationId(validationId, IRegistrationItemView.VALUETYPE_TEXTFIELD);
        mRegistrationBasicInformationItemForDob.SetValue(value);
        return mRegistrationBasicInformationItemForDob;
    }

    @Override
    public IRegistrationItemView CreatePhoneNumberItemView(String label, int type, String value, int validationId) {
        mRegistrationBasicInformationItemForPhoneNumber.SetEventListener(this);
        mRegistrationBasicInformationItemForPhoneNumber.SetLabel(label);
        mRegistrationBasicInformationItemForPhoneNumber.SetValue(value);
        mRegistrationBasicInformationItemForPhoneNumber.SetValidationId(validationId, IRegistrationItemView.VALUETYPE_TEXTFIELD);
        return mRegistrationBasicInformationItemForPhoneNumber;
    }

    @Override
    public IRegistrationItemView CreateEmailItemView(String label, int type, String value,
                                                     int validationId) {
        mRegistrationBasicInformationItemForEmail.SetEventListener(this);
        mRegistrationBasicInformationItemForEmail.SetLabel(label);
        mRegistrationBasicInformationItemForEmail.SetValue(value);
        mRegistrationBasicInformationItemForEmail.SetValidationId(validationId,
                IRegistrationItemView.VALUETYPE_TEXTFIELD);
        mRegistrationBasicInformationItemForEmail.mRegistrationItemTextTypeEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
        return mRegistrationBasicInformationItemForEmail;
    }

    @Override
    public IRegistrationItemView CreateGenderItemView(String label, int type,
                                                      IStringList valueList, int validationId, int GenderType) {
        mRegistrationBasicInformationItemForGender.SetEventListener(this);
        mRegistrationBasicInformationItemForGender.SetLabel(label);
        mRegistrationBasicInformationItemForGender.SetValidationId(validationId,
                IRegistrationItemView.VALUETYPE_RADIO_BUTTON);
        mRegistrationBasicInformationItemForGender.SetValueList(type, valueList);
        mRegistrationBasicInformationItemForGender.clearRadioButtons();
        mRegistrationBasicInformationItemForGender.SetValueForSwitch(GenderType);
        return mRegistrationBasicInformationItemForGender;
    }

    @Override
    public void OnErrorIconClick(int validationId) {
        //NA
    }

    @Override
    public void OnCalendarIconClick() {
        mRegistrationBasicInformationController.OnCalendarDateTimeIconClicked();
    }

    @Override
    public void OnSwitchButtonClick(int validationId, boolean isChecked) {
        //NA
    }

    @Override
    public void OnRegistrationItemEditCompleted(String content, int validationId) {
        mRegistrationBasicInformationController.OnRegistrationItemEditCompleted(validationId, content);
    }

    @Override
    public void OnSpinnerItemSelected(int validationId, int position) {
        switch (validationId) {
            case RegistrationValidator.VALIDATE_PRACTICE:
                mRegistrationBasicInformationController.OnPracticeItemSelected(position);
                break;

            case RegistrationValidator.VALIDATE_PROVIDER:
                mRegistrationBasicInformationController.OnProviderItemSelected(position);
                break;
        }
    }

    @Override
    public Presenter GetPresenter() {
        return mRegistrationBasicInformationController;
    }

    @Override
    public String GetClassName() {
        return getClass().getSimpleName();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        OnDestroy();
    }

    @Override
    public void OnDestroy() {
        mRegistrationEnterYourBasicInformationLabel = null;
        if (mRegistrationBasicInformationItemForFirstName != null) {
            mRegistrationBasicInformationItemForFirstName.OnDestroy();
            mRegistrationBasicInformationItemForFirstName = null;
        }

        if (mRegistrationBasicInformationItemForLastName != null) {
            mRegistrationBasicInformationItemForLastName.OnDestroy();
            mRegistrationBasicInformationItemForLastName = null;
        }

        if (mRegistrationBasicInformationItemForNickName != null) {
            mRegistrationBasicInformationItemForNickName.OnDestroy();
            mRegistrationBasicInformationItemForNickName = null;
        }

        if (mRegistrationBasicInformationItemForPhoneNumber != null) {
            mRegistrationBasicInformationItemForPhoneNumber.OnDestroy();
            mRegistrationBasicInformationItemForPhoneNumber = null;
        }

        if (mRegistrationBasicInformationItemForDob != null) {
            mRegistrationBasicInformationItemForDob.OnDestroy();
            mRegistrationBasicInformationItemForDob = null;
        }

        if (mRegistrationBasicInformationItemForEmail != null) {
            mRegistrationBasicInformationItemForEmail.OnDestroy();
            mRegistrationBasicInformationItemForEmail = null;
        }

        if (mRegistrationBasicInformationItemForGender != null) {
            mRegistrationBasicInformationItemForGender.OnDestroy();
            mRegistrationBasicInformationItemForGender = null;
        }

        if (mRegistrationBasicInformationItemForPractice != null) {
            mRegistrationBasicInformationItemForPractice.OnDestroy();
            mRegistrationBasicInformationItemForPractice = null;
        }

        if (mRegistrationBasicInformationItemForProvider != null) {
            mRegistrationBasicInformationItemForProvider.OnDestroy();
            mRegistrationBasicInformationItemForProvider = null;
        }

        ViewUtils.UnbindReferences(mRegistrationBasicInformationMainLayout);
        ViewUtils.UnbindReferences(getView());
    }

    @Override
    public void onFocusChange(View view, boolean hasFocus) {
        if (!hasFocus) {
            CustomTextInputEditText editText = (CustomTextInputEditText) view;

            mRegistrationBasicInformationController.OnRegistrationItemEditCompleted((int) view.getTag()
                    , editText.getText().toString());
        }
    }
}

0 个答案:

没有答案