androidandroid-edittextimeoptions

Changing imeOptions from a text watcher


I am trying to change the imeOptions from a textwatcher, On detecting "@" symbol on a edittext I need to change its imeOptions from "Go" to "Done". Please advice.

 etSample.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            if ((charSequence+"").contains("@")){
                etSample.setBackgroundColor(Color.BLACK);
                etSample.setTextColor(Color.WHITE);
                etSample.setImeOptions(EditorInfo.IME_ACTION_NEXT);
                etSample.requestFocus();
            }else {
                etSample.setBackgroundColor(Color.WHITE);
                etSample.setTextColor(Color.BLACK);
                etSample.setImeOptions(EditorInfo.IME_ACTION_DONE);
                etSample.requestFocus();
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    });

This is not working(it will show done always)


Solution

  • Try to replace etSample.requestFocus() with etSample.setInputType(InputType.TYPE_CLASS_TEXT)