Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it worth waiting a couple of milliseconds on a TextChanged event?

I have a textfield for a filter customers action on a mobile device. I am wondering if I should wait for a few milliseconds before launching my code when the user typed in less then 3 chars, and only execute the code if the text is longer or equal than 3 chars.

The executed code takes longer(sql like syntax on a larger database), and the user sees hang-outs on the listview.

What do you think?

like image 938
Pentium10 Avatar asked Feb 14 '10 20:02

Pentium10


2 Answers

Delaying SQL queries on text changed events is a good idea indeed. We do use this technique throughout Android. We also always make sure to cancel any previous query. For instance, if the user types "ab", and we post a message to start a query after the user typed "a", we cancel that message when the user types "b".

like image 69
Romain Guy Avatar answered Sep 22 '22 08:09

Romain Guy


If the user sees hang-outs when your code is launched, I wouldn't launch it right away.

Assuming the query executes on the fly based on the user's input, I would wait until you the user types enough chars to process a lighter query and wouldn't bog down the UI. Especially using %LIKE% syntax, less char's you have to work with, means a larger query and a longer wait-time for the user.

like image 42
Anthony Forloney Avatar answered Sep 19 '22 08:09

Anthony Forloney