Hi Guys,
I want a similar searching functionality like Twitter,etc apps. User will enter text and as per the text entered, user should get the updated set of options to choose from. I am fetching data from external database for that. Currently I used a web-service and passed the data to be searched in it, which gives me relevant results. I am calling that web service on onTextChanged event of EditText. But this causes me to fire that web-service every time a letter has been added. Can someone suggest a more efficient solution, as it is not giving me results as fast as Twitter app. Every time I ping database for each letter entered, which causes delay in showing results.
Related
I'm writing an android application that has a search feature that needs to autocomplete from a list of stores. This list will only have up to a few thousand stores in it.
My current methodology is to send a LIKE query to the database every few hundred ms after the user has stopped typing and to populate the autocomplete list with these results.
Would using this method be stressful to the database?
It has been suggested to me that this wouldn't work because making continuous calls would be poor for users with a slow connection and that I should load all the stores into memory and filter from there.
At my work I ran into a similar problem a few months back. The contents of a text box filled by the user were supposed to filter their available options to choose from in a list of strings. The list needed to be updated every time the user typed a key so database calls to fetch records that matched their text were being made several times a second.
This ended up being wayy to slow to update as someone was typing, and this was only with several thousand records and with a server that was being accessed on site.
If you want to update as quickly as someone can type, making that many database calls simply won't do. Users will get pretty antsy having to let their phone buffer to type in some text.
In Short: Make one databse call and load it up onto the phone, and run your filter algorithm from there.
Regularly syncing the list of stores from your back end to the user's device and implementing autocomplete locally is the best way to go.
The JobScheduler API provides a flexible way to set constraints on your background syncing processes.
i trying to implement auto search mechanism in android like google. Here when i enter some words then display related search results in list view. For example i entered 3 letters then display related search results from server, again i will add another letter to previous 3 letters then automatically display related search results with out click search button.I don't know how to do it, every time api calling. How to use Search view option from android xml for searching?
On client side you should with the help of AutoCompleteTextView, Adapter, HTTPClient and other stuff you handle sending a request to server. On server side you implement Filter after querying database. After filter is done - respond result and via AutoCompleteTextView you show suggestions. Then via Adapter you set list.
Very nice example
Now when you know which way to search better use google. It is rich on that kind of info and if you face some problems - ask new question with exact! problem.
hope it is helpful.
Hi everyone i'am currently developing an android game, it uses your phone number when you first use the game(it is for an identification of the user).
It is an social game at some time when the user requests it returns a list of people who are currently online(playing the game),as json array(there phone number,name,photo)and from the data received you need to filter it out and display in two list views. The filtering done by this method:
1)Each element from JSON data(each person)if there phone number is found in user's contact list then is displayed in the first listview
2)if the number is not found in users contact list it is displayed in second listview.
But my doubt is that if the JSON array returns details of 10 people, you need to check for this 10 people whether they are in user's contact list.And does this kind of a technique takes a lot of time and creates delay in the UI..?
If yes please suggest me some other method.
Also please tell me how can I check whether a number is in user's contact list(I make the users upload there number to server without any country code).
So please in the number finding method you need to end the checking one a number has been fully completed.(starting from the end.
eg : 8086934565 (no saved in database) +918086934565(no in contact list)
then we need to start from last so that
5==5 then continue
6==6 then continue
till any of the no (+918086934565 or 8086934565) ends without breaking any equivalent condition.
eg for numbers +918086934565 and 8086933365
checking from the last
5==5,6==6, 5!=3 there the equivalent condition goes wrong and hence it should get out from the loop with a flag ie the numbers are not equal.
Please write me the function to do this or tell me an alternative method.
Any help would be appreciable.
Thanks.
Ugh, that's painful to read...haha...You're suggesting using phone numbers to identify users in a multiplayer matchmaking scenario? That's taboo...If you return a JSON array of users phone numbers, names, and photos, your app will almost certainly be permanently banned from the market and possibly your entire account. That is about the biggest security risk that I can possibly think of, you might as well have a textfield where everybody types in their social security number and it posts it to craigslist. Basically any of your users could just repeatedly initiate games with people and get names photos and phone numbers of 10 random people at a time by capturing the plain text JSON data coming back. If I were you I'd look into the facebook sdk for authentication or Google Play Game Services for multiplayer matchmaking unless the core mechanics of your game rely on phone numbers specifically, in which case by it's very nature is just not going to fly with users. Asking someone to write you a function to do that is most likely never going to happen on stackoverflow. I'm not even going to get into the last part of the question...This has to be a troll attempt...lol
I have a SearchView in ActionBar and I'm using onQueryTextListener with it. I have a Listview in activity's layout to which the ActionBar belongs. There are two Textviews in ListView. So, as user enter text into searchview, a web query(api) is performed on the text and the results(array) received are used to populate the listview. Just like AutoCompleteTextView but instead displaying results in listview.
I am using a HandlerThread to perform this query and populating the listview and I have implemented it in onQueryTextChange which is working.
But, the problem is that it takes long time to display results. The results are displayed after user is done entering input. However, I want results to be displayed as user enter text(Like Google suggest). How can I do this?
I imagine Google uses cached results on their servers to speed up the response to queries. You could use something like MemCache or Varnish to provide results faster. If the results require searches you could also improve the speed by using a search engine like Apache Solr or Lucene.
Google will also have very good server infrastructure with cached results being located all over the world so always near the user. The results will probably vary from server to server so that they give what local users want. I remember calculating a few years back based on trying to improve response times for online gaming that Europe is something like a tenth of a second from North America.
You can also fake this information. You can download results that you anticipate a user would want on to their device and fill the autocomplete from a database on the device. A request can also be sent to the server at the same time and the autocomplete results updated once the response is received from the server. This to some extent depends on the complexity of what you are searching. If there are only a limited number of results you could easily store them all on the device.
Hey I'm using an AutoCompleteTextView in my android app the data that populates the textView is retrieved from a web API. the data is retrieved in JSON format and then added to a matrix cursor. the app then uses a cursor loader and a content provider to load data to the textview in the background. I would like to filter the data as I enter characters in the textview currently it loads all the data without filtering as I enter. Is there a way to filter the data in the cursor and have it loaded by the cursorloader without having to request the web API again
I think your approach is incorrect. Why do you need to save the received data, particularly given that that data is intermittent and the user is still typing? Also you need to:
1) start Data fetching only when a user pauses typing (to prevent a bunch of requests to a server after every entered character)
2) Suggestions should be shown only if the user enters a string of some minimum length (no reason to start data fetching for string of 2 or 3 characters)
Check out this explanation from Alex Melnykov about how he used 'AutoCompleteTextView With Suggestions From a Web Service' for his app Booktracker.