You can do it using setOnKeyListener or using a textWatcher like:
Set text watcher editText.addTextChangedListener(textWatcher);
then call
private TextWatcher textWatcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
//after text changed
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
};
First you will need to setup listener if keyboard is show or hide.
If keyboard is showing then probably user is typing, otherwise done typing.
final View activityRootView = findViewById(android.R.id.content);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
//r will be populated with the coordinates of your view that area still visible.
activityRootView.getWindowVisibleDisplayFrame(r);
int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
isTyping = true;
} else {
//to make sure this will call only once when keyboard is hide.
if(isTyping){
isTyping = false;
}
}
}
});
both @Reno and @Vinayak B answers together if you want to hide the keyboard after the action
You can do it using setOnKeyListener or using a textWatcher like:
Set text watcher
editText.addTextChangedListener(textWatcher);
then call
I have done something like this abstract class that can be used in place of TextView.OnEditorActionListener type.
Simple to trigger finish typing in EditText
worked for me , if you using java convert it
In Kotlin
A different approach ... here is an example: If the user has a delay of 600-1000ms when is typing you may consider he's stopped.
Okay this will work 100% for sure.
First you will need to setup listener if keyboard is show or hide. If keyboard is showing then probably user is typing, otherwise done typing.