2

I have an EditText. I use setOnEditorActionListener to listen to each letter that a user types. But that does not seem to be working. I put a println statement in the function to see it it is reached, but it's never called. Here is the EditText. What is it missing?

    <EditText
            android:id="@+id/email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="5dp"
            android:drawableRight="@drawable/my_img"
            android:hint="@string/email_hint"
            android:imeActionId="@+id/login"
            android:inputType="textNoSuggestions|textVisiblePassword"
            android:maxLines="1"
            android:singleLine="true"
            android:textColor="#000000" />
Cote Mounyo
  • 13,817
  • 23
  • 66
  • 87

3 Answers3

5

You can register a TextWatcher on the EditText if you want to listen to every letter the user types in:

editText.addTextChangedListener(new TextWatcher() {...} );
Ahmad
  • 69,608
  • 17
  • 111
  • 137
1

Try this in the activity that is using EditText object.

EditText emailText = (EditText) findViewById(R.id.email);

emailText.addTextChangedListener(new TextWatcher() {

    public void onTextChanged(CharSequence s, int start, int before, int count) {

    // put a debug statement to check

    }

    @Override
    public void afterTextChanged(Editable s) {

    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }
    });
sjdutta
  • 376
  • 1
  • 5
1

You're looking for a TextWatcher. The callbacks are self-explanatory. Depending on what you need, you may want to add your logic code to onTextChanged, beforeTextChanged or afterTextChanged. In the CharSequence s object you can get the text of the EditText:

EditText mEditText = (EditText) findViewById(R.id.email);
mEditText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {

            // TODO Auto-generated method stub
            // Here you may access the text from the object s, like s.toString()

}

@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            // TODO Auto-generated method stub
        }

@Override
public void afterTextChanged(Editable s) {

            // TODO Auto-generated method stub
        }
    });
MetalCraneo
  • 335
  • 1
  • 4
  • 14