1

What is the best way to manage to handle the typing-timeout?

I tried the code like this (inspired by the code here):

public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
//...
    Message msg = Message.obtain(messageHandler, MESSAGE_TEXT_CHANGED, arg0.toString());
    messageHandler.sendMessageDelayed(msg, 1000 );
//...
}

but in the logs I can see that the geocoder gets invoked upon each key-press, no matter how fast I type. I'd like to have the same behaviour like Javascript's setTimeout(...) function has.

Any help appreciated

Community
  • 1
  • 1
injecteer
  • 20,038
  • 4
  • 45
  • 89

1 Answers1

1

You could cancel the previous messages sent to the handler when a new key is pressed:

Message msg = Message.obtain(messageHandler, MESSAGE_TEXT_CHANGED, arg0.toString());
messageHandler.removeMessages(MESSAGE_TEXT_CHANGED);
messageHandler.sendMessageDelayed(msg, 1000 );
Sebastian Breit
  • 6,137
  • 1
  • 35
  • 53