Skip to content

Instantly share code, notes, and snippets.

@ammarques
Last active December 2, 2015 17:48
Show Gist options
  • Save ammarques/0d5d3240dc5598fc12f1 to your computer and use it in GitHub Desktop.
Save ammarques/0d5d3240dc5598fc12f1 to your computer and use it in GitHub Desktop.
/*
* The function searchPlaces can be called continuously, no matter how many times it got invoked
* the Handler will remove all the last sequence request, and execute the last one.
* */
String fieldValue = "";
final private Handler handler = new Handler();
final private Runnable runnable = new Runnable() {
@Override
public void run() {
Log.i("searchPlaces",fieldValue);
// Dispare aqui a ação desejada.
}
};
private void searchPlaces(final View v){
fieldValue = ((EditText) v).getText().toString(); //get the field value and add to a global variable.
handler.removeCallbacks(runnable); // remove the previous postDelayed associated to that runnable.
handler.postDelayed(runnable, 1000); // create a new PostDelayed with the global runnable.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment