Skip to content Skip to sidebar Skip to footer

Remove Focus From A Edittext In Android

I have two EditTexts and one CheckBox and a Button in my layout in the above order. After entering the values to the EditText, the user has to accept terms and conditions by clicki

Solution 1:

Using onCheckedChangeListener of Check Box you can do this. Just apply this on your Activity's onCreate()

chb1 = (CheckBox) findViewById(R.id.pm_check_t_and_c);
        chb1.setOnCheckedChangeListener(newCompoundButton.OnCheckedChangeListener() {
            @OverridepublicvoidonCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (chb1.isChecked()) {
                    edt1.clearFocus();
                    InputMethodManagerimm= (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(edt1.getWindowToken(), 0);
                } else {
                    edt1.requestFocus();
                }

            }
        });

Solution 2:

checkBox.setOnClickListener(newView.OnClickListener() {
        @OverridepublicvoidonClick(View v) {
            editText.setFocusable(false);
        }
    });

Add above OnClickListener to check box.

Solution 3:

checkBox.setOnClickListener(newView.OnClickListener() {
        @OverridepublicvoidonClick(View v) {
            editText.setFocusable(false);
        }
    });

After removing focus, please do one more..

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

Solution 4:

Post a Comment for "Remove Focus From A Edittext In Android"