1

I am beginner in android but not in Java , and have a problem.

Took hours losses in my application ignores keyboard to enter and you put the code below. What I want is that when I do a thing to enter and go. Since it seems redundant and have not optimal OK button when you have an OK in the Enter itself.

    t_Num = (EditText) findViewById(R.id.eTT);
    ...
    t_Num.setFocusableInTouchMode(true);
    t_Num.requestFocus();
    t_Num.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            System.out.println("entra en Onkey" + event.toString());
            if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
                    (keyCode == KeyEvent.KEYCODE_ENTER)){
                    tV.setText("OK");
                    System.out.println("Press OK");

                    return true;
                }
            return false;
        }
    });

Whit this code i get spam the keypress , but not spam the keypress OK.

And XML:

<EditText
    android:layout_width="75dp"
    android:layout_height="wrap_content"
    android:inputType="numberSigned|phone"
    android:digits="-0123456789"
    android:ems="10"
    android:id="@+id/eTT"
    android:imeActionLabel="@string/OK"
    android:maxLength="6"
    android:maxLines="1"
    android:layout_alignBottom="@+id/tV2_1"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_toRightOf="@+id/btnOk"
    android:layout_toEndOf="@+id/btnOk" />

thanks for help
PD : I search in this page but not get solution , font1 , font2 , etc...
I use search :)

Community
  • 1
  • 1
CodeNoob
  • 345
  • 4
  • 17
  • 1
    see http://developer.android.com/reference/android/widget/TextView.OnEditorActionListener.html – njzk2 Dec 29 '14 at 21:38
  • But i use EditText , no TextView , ¿this inputs is equals? EditText can't edit message but TextView can add text to user but thx. – CodeNoob Dec 29 '14 at 21:42
  • 1
    `TextView (...) Known Direct Subclasses (...) EditText` – njzk2 Dec 29 '14 at 21:49

1 Answers1

1

Try this:

editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_GO) {
                //your code
                return true;
            }
            return false;
        }
    });

This is if the editText has

android:imeOptions="actionGo"

in its xml. Same should apply with Enter. Just change the EditorInfo action.

EditText is a subclass of TextView.

DejanRistic
  • 2,039
  • 18
  • 13
  • Perfect, but i add IME_ACTION_SEND is best for mi applycation y use The action key performs a "next" operation, taking the user to the next field that will accept text. Corresponds to IME_ACTION_NEXT [this link for any need more information](http://developer.android.com/reference/android/widget/TextView.html#attr_android:imeOptions) – CodeNoob Dec 29 '14 at 23:55