I have to run a function just once when after the user stops typing but my function runs multiple times.I have detected when a user stops typing but can't execute my function just once.
@Override
public void onTextChanged(CharSequence charSequence, final int i, final
int i1, final int i2) {
Timer timer = new Timer();
//Run after user stops typing
TimerTask tt = new TimerTask() {
@Override
public void run() {
Date myRunTime = new Date();
if ((lastTypeTime.getTime() + 1000) <= myRunTime.getTime()) {
Handler h = new Handler(Looper.getMainLooper());
h.post(new Runnable() {
@Override
public void run() {
Log.i("t_type", "Type Finish");
//Issue : This is printed multiple time.
}
});
} else {
Log.i("t_cancel", "cancel");//cancel
}
}
};
timer.schedule(tt, 2000);//two second delay after user stops typing
}