Last active
February 29, 2016 12:24
-
-
Save vuhung3990/950c901e9811a30f33e8 to your computer and use it in GitHub Desktop.
Search delay idea
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
// private long currentSearchTime; | |
// private Handler handlerSearch; | |
// private Runnable runableSearch; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
handlerSearch = new Handler(); | |
runableSearch = new Runnable() { | |
@Override | |
public void run() { | |
System.out.println("Query..."); | |
} | |
}; | |
} | |
@Override | |
public boolean onQueryTextChange(String newText) { | |
// TODO ion (get from server) | |
// cursor_search.addRow(new String[] { "0", "dsaasd" }); | |
handlerSearch.postDelayed(runableSearch, 1000); | |
if (currentSearchTime + 1000 > System.currentTimeMillis()) { | |
System.out.println("typing..."); | |
handlerSearch.removeCallbacksAndMessages(null); | |
handlerSearch.postDelayed(runableSearch, 1000); | |
} | |
currentSearchTime = System.currentTimeMillis(); | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment