-2

I want to do something with a text field in my program that as soon as the user presses a key on keyborad and writes the first character of a word a special task begin executing something like click listener on a button but for a text field

I will be thankful if you help me

YouTah
  • 13
  • 2

2 Answers2

0

Do you mean TextView or EditText?

In case of EditText you can use a TextWatcher. Here you can use the method "onTextChanged".

Community
  • 1
  • 1
TheOnlyJakobob
  • 541
  • 3
  • 14
0

TextView dont receive key pressed. You need an EditText to do this.

Follow the code below:

editText.addTextChangedListener(new TextWatcher() {          
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {                                   
   //here is your code
}                       
@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                          
}
});
João Marcos
  • 3,872
  • 1
  • 19
  • 14