Android Edittext - Finished Typing Event

android EditText - finished typing event

When the user has finished editing, s/he will press Done or Enter

((EditText)findViewById(R.id.youredittext)).setOnEditorActionListener(
new EditText.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH ||
actionId == EditorInfo.IME_ACTION_DONE ||
event != null &&
event.getAction() == KeyEvent.ACTION_DOWN &&
event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
if (event == null || !event.isShiftPressed()) {
// the user is done typing.

return true; // consume.
}
}
return false; // pass on to other listeners.
}
}
);

How to detect if users stop typing in EditText android

This is how I did and works for me!

long delay = 1000; // 1 seconds after user stops typing
long last_text_edit = 0;
Handler handler = new Handler();

private Runnable input_finish_checker = new Runnable() {
public void run() {
if (System.currentTimeMillis() > (last_text_edit + delay - 500)) {
// TODO: do what you need here
// ............
// ............
DoStuff();
}
}
};

EditText editText = (EditText) findViewById(R.id.editTextStopId);
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged (CharSequence s,int start, int count,
int after){
}
@Override
public void onTextChanged ( final CharSequence s, int start, int before,
int count){
//You need to remove this to run only once
handler.removeCallbacks(input_finish_checker);

}
@Override
public void afterTextChanged ( final Editable s){
//avoid triggering event when text is empty
if (s.length() > 0) {
last_text_edit = System.currentTimeMillis();
handler.postDelayed(input_finish_checker, delay);
} else {

}
}
}

);

How to Listen Android keyboard Close Event after Typing finished in EditText?

finally i got the answer for Next/Done/search AND enter key press like this

@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(event !=null){
if(actionId == EditorInfo.IME_ACTION_SEARCH ||
actionId == EditorInfo.IME_ACTION_NEXT ||
actionId == EditorInfo.IME_ACTION_DONE ||
event.getAction() == KeyEvent.ACTION_DOWN &&
event.getKeyCode() == KeyEvent.KEYCODE_ENTER){
if (!event.isShiftPressed()) {

Log.e("", "FINISHED Typing : "+v.getText().toString());
return true; // consume.
}
}
}
else{
if(actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_NEXT || actionId == EditorInfo.IME_ACTION_DONE){
Log.e("", "Next/Done/Search Pressed");
return true;
}

}
return false;
}

also for the Keypad dismiss i customized the editText and override the method onKeyPreIme into that. Whenever i need the edittext , i am using this edittext. this solved my issue.

@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
if (event.getAction()!=KeyEvent.ACTION_DOWN){
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
dispatchKeyEvent(event);
//do whatever you want to do here, when keypad dismiss on EditText
return false;
}
}
return super.onKeyPreIme(keyCode, event);
}

Knowing when Edit text is done being edited

By using something like this

 meditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
switch (actionId){
case EditorInfo.IME_ACTION_DONE:
case EditorInfo.IME_ACTION_NEXT:
case EditorInfo.IME_ACTION_PREVIOUS:
yourcalc();
return true;
}
return false;
}
});

How do I select all the text in an editText after the user is finished typing in it?

You can use Rx's debounce to do that,

    RxTextView.textChanges(editText)
.debounce(3, TimeUnit.SECONDS)
.subscribe { textChanged: CharSequence? ->
Log.d(
"TAG",
"Stopped typing!"
)
editText.selectAll()
}

android edittext onchange listener

First, you can see if the user finished editing the text if the EditText loses focus or if the user presses the done button (this depends on your implementation and on what fits the best for you).
Second, you can't get an EditText instance within the TextWatcher only if you have declared the EditText as an instance object. Even though you shouldn't edit the EditText within the TextWatcher because it is not safe.

EDIT:

To be able to get the EditText instance into your TextWatcher implementation, you should try something like this:

public class YourClass extends Activity {

private EditText yourEditText;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.main);
yourEditText = (EditText) findViewById(R.id.yourEditTextId);

yourEditText.addTextChangedListener(new TextWatcher() {

public void afterTextChanged(Editable s) {

// you can call or do what you want with your EditText here

// yourEditText...
}

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

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

Note that the above sample might have some errors but I just wanted to show you an example.

How to receive final afterTextChanged event, for EditText with spelling suggestion (without turning off)

This is a correct solution to solve my faced problem. The key is to use

editText.post

Solution

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

final EditText editText = findViewById(R.id.edit_text);

editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

@Override
public void afterTextChanged(final Editable editable) {
final String originalString = editable.toString();

editText.post(new Runnable() {
@Override
public void run() {
String text = editText.getText().toString();
if (text.equals(originalString)) {
Log.i("CHEOK", originalString);
}
}
});
}
});
}
}

The idea is, when the time posted function is executed, editText.getText() is returning a complete text (abc\ndef)

Adding if (text.equals(originalString)), is to ignore 2 intermediate texts in between (def and abc\n)



Related Topics



Leave a reply



Submit