Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditText input method action not working when setting imeActionLabel

I have an Edittext with imeoptions asactiongo. and I triggered my event when pressing soft keyboard enter button.

mModelId.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
           // if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
            if (actionId == EditorInfo.IME_ACTION_GO) {

                id = mModelId.getText().toString();
                System.out.println("Model id in Edittext:-"+ id);
                Toast.makeText(getActivity(), "You entered "+id, Toast.LENGTH_LONG).show();
                System.out.println("Before Call Volley");
                callVolley();
                handled = true;
            }
            return handled;
        }
    });

Everything works fine but when I add actionlabel to enter key the event is not firing. mModelId.setImeActionLabel("Search Model", KeyEvent.KEYCODE_ENTER);. What may be the problem?

like image 849
NIPHIN Avatar asked Oct 10 '14 12:10

NIPHIN


2 Answers

try this

declare edittext and OnEditorActionListener() like this

mModelId = (EditText) findViewById(R.id.edittext_id);
mModelId.setImeActionLabel("Search Model", KeyEvent.KEYCODE_ENTER);
mModelId.setOnEditorActionListener(new OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
         boolean handled = false;

         if (actionId == KeyEvent.KEYCODE_ENTER) {

              id = mModelId.getText().toString();
              Toast.makeText(getActivity(), "You entered "+id,    Toast.LENGTH_LONG).show();
              callVolley();
              handled = true;
            }
            return handled;
        }
});

and you use imeoptions as actionGo then revome it, i think it override ImeActionLabel once try this and reply

like image 150
Lokesh Avatar answered Oct 10 '22 02:10

Lokesh


  1. Supply a value for EditorInfo.actionId used when an input method is connected to the text view.

    numberEditor.mInputContentType.onEditorActionListener.onEditorAction( this, EditorInfo.IME_NULL, event))

  2. Supply a value for EditorInfo.actionLabel used when an input method is connected to the text view.

Must be a string value, using '\;' to escape characters such as '\n' or '\uxxxx' for a unicode character.

like image 35
Faakhir Avatar answered Oct 10 '22 01:10

Faakhir