Reputation: 997
I am doing such thing
Add a timer to the autocompletes for .5 seconds before
sending a request to the server. If the user types before the
.5 timer, reset the timer.
i am trying inside of onTextChanged()
public void onTextChanged(CharSequence s, int start, int before, int count) {
/* String newText = s.toString();
if(!newText.trim().equals(""))
Autocompletes_Timer(newText);*/
}
private Handler handler;
private void Autocompletes_Timer(final String newText) {
if(handler!= null)
handler.removeCallbacksAndMessages(null);
handler = new Handler();
handler.postDelayed(runnable(newText), 500);
}
please suggest me.
Upvotes: 0
Views: 73
Reputation: 1457
public class SomeClass extends Activity implements TextWatcher {
private Handler serverHandler;
@Override
public void onCreate(Bundle savedInstance) {
serverHandler = new Handler();
...
}
...
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(!newText.trim().equals(""))
serverHandler.removeCallbacksAndMessages(null);
serverHandler.postDelayed(new Runnable() {
@Override
public void run() {
//Do somthing there
}
}, 500);
}
}
}
Upvotes: 1
Reputation: 1173
try that:
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//Do somthing there
}
}, 5000);
Upvotes: 0