I have autocomplete in my application. There, if I start typing letters, autocomplete does not take much time to process the JSON file. I am using addTextChangedListener, and because of this the input letters are not so smooth. I would like to set a timeout before the search data in JSON.
Object mObj[] = { dep, arr }; for (int mI = 0; mI < mObj.length; mI++) { ((AutoCompleteTextView) mObj[mI]) .addTextChangedListener(new TextWatcher() { public void onTextChanged(final CharSequence s, int start, int before, int count) { setListViewAuto(s, mass); } public void beforeTextChanged(CharSequence s, int start, int count, int after) {
UPD: I do this:
final Object mObj[] = { dep, arr }; for (int mI = 0; mI < mObj.length; mI++) { ((AutoCompleteTextView) mObj[mI]) .addTextChangedListener(new TextWatcher() { private Handler autoHandler = new Handler() { @Override public void handleMessage(Message msg) { if (msg.what == MESSAGE_TEXT_CHANGED) { String enteredText = (String) msg.obj; setListViewAuto(enteredText); } } }; public void onTextChanged(final CharSequence s, int start, int before, int count) { massListAuto = new ArrayList<String>(Arrays .asList(mass)); String enteredText = s.toString(); autoHandler.removeMessages(MESSAGE_TEXT_CHANGED); final Message msg = Message.obtain(autoHandler, MESSAGE_TEXT_CHANGED, enteredText); autoHandler.sendMessageDelayed(msg, AUTOCOMPLETE_DELAY); } public void beforeTextChanged(CharSequence s, int start, int count, int after) {
But I get a message: this handler class must be static or a leak may occur
source share