Reputation: 1823
In my application I had struck .Required your help.
I have to detect which character is pressed during writing into the EditText Fields.
Means while writing if I pressed key "a" from keyboard; application move to next step.
like this way. so, How Can I detect the character into Real time in Android?.
I don't know but onkeyUp and Textwatcher may helpfull to me or not?
The code display below I found from StackOverflow but didn't work for me. code:
EditText editText= (EditText)findViewById(R.id.editText2);
editText.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable e) {
String textFromEditView = e.toString();
validateText(textFromEditView);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
s = "sat";
return;
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
//nothing needed here...
}
});
Upvotes: 0
Views: 843
Reputation: 3578
edittext.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v , int keyCode , KeyEvent event) {
// TODO Auto-generated method stub
if (keyCode == event.KEYCODE_A) {
// Do what you want here
}
return false;
}
});
Upvotes: 1