Loose Ends

To finish up the Suggest example, here are a few utility functions used in other places:

suggest/src/main/java/org/example/suggest/MainActivity.java
 
/** Request an update to start after a short delay */
 
private​ ​void​ queueUpdate(​long​ delayMillis) {
 
// Cancel previous update if it hasn't started yet
 
guiThread.removeCallbacks(updateTask);
 
// Start an update if nothing happens after a few milliseconds
 
guiThread.postDelayed(updateTask, delayMillis);
 
}
 
 
/** Modify list on the screen (called from another thread) */
 
public​ ​void​ setSuggestions(​List​<​String​> suggestions) {
 
guiSetList(suggList, suggestions);
 
}
 
 
/** All changes to the GUI must be done in the GUI thread */
 
private​ ​void​ guiSetList(​ ...

Get Hello, Android, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.