Last active
December 2, 2015 17:48
-
-
Save ammarques/0d5d3240dc5598fc12f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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