views:

233

answers:

5

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?

+1  A: 

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.

Anthony Forloney
A: 

I would try using the same approach as android native applications since the source code is available. For example Contacts.

Check what they do when you search for a contact.

Macarse
I don't understand what they do, it looks to complicated for me. Can you explain in words?
Pentium10
I didn't check what they do. I just told you where you could look for.
Macarse
Contacts performs the query on another thread. It starts the query as soon as it gets the first input, and keep running the query as often as it can until it has caught up with whatever the user has typed so far. This allows it to be responsive to both single letters, and a batch of letters that are typed faster than queries can be run.
hackbod
A: 

Some applications also perform validation of inputs when the focus moves to another input field and don't check the input while it is being edited. I'm not sure if it's a good thing or not (I find it a bit confusing), but it's definitely one way to solve the problem...

Tomas Petricek
+4  A: 

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".

Romain Guy
can you share code?
Pentium10
A: 

On the iPhone if you see lag as the user is typing after you initiate a search, you probably need to move the querying operation to a background thread, with the ability to cancel old searches as RG mentioned doing.

It might make sense to delay slightly for the first few characters but then have no delay beyond that - after about three to four you probably have enough characters to start to return meaningful results.

Kendall Helmstetter Gelner