Call a Web service to get the search result while using search Bar

You must Login before you can answer or comment on any questions.

I have implemented a tableView with a searchBar added to it. I want to call a service when user start typing the search keyword in the search bar. I know that I can call the service in the change event listener that will call the service.

The problem I am facing is that for every change in the search bar It is not good to call a service. So what is the efficient approach of using search bar when the search result is coming from a service call or what we can do to make the search efficient.

For example: the search functionality on Apple's App store

2 Answers

Accepted Answer

Then you need to use the change event. If you would like to call the service once you have types in x amount oof characters you can check the length of the input string before calling the service.

Ajeet,

Try to call webservice in return event listener like..

var search = Titanium.UI.createSearchBar({
    top : 0,
    height : 44,
    hintText : "Search",
    barColor : '#dedede',
 
});
win.add(search);
 
search.addEventListener('return', function(e) {
    // function()
});

— answered 8 months ago by Ritesh .
answer permalink
2 Comments
  • This is calling a service when I press the return key. I want it to be on the fly... like as soon you type the word 'ele' it should give you the list say [elephant, elegant, elevate...etc]

    The search should be done while I am typing..

    — commented 8 months ago by Ajeet pratap Maurya

  • Is this entry in the docs what you are looking for ? Of course, you might have to do some throttling ...

    — commented 8 months ago by Thierry Godfroid

Your Answer

Think you can help? Login to answer this question!