Searching for contacts with smartface - android

I would like to show my users a list of their contacts with a phone number. I tried to create a filtered list using the getAll method, but I found it too slow.
So I would like to allow the user to search for a name, and then I would return the contacts who name match the query. Is this possible in smartface?

Yes, it is possible.
You can use a repeatbox object in order to list contacts, and use a dataset for binding of that repeatbox. And when you write the appropriate sql statement(select) into that dataset, it will work for search.
Or you can search google for some search algorithms and use one of them. For example, you can use an editbox object, or a searchbar objects, and when its text is changed you can call your search function.

Related

Usin SimpleCursorAdapter confusion

I have a ContentProvider implementation in my app which works fine. I have a table called elements where the user can store a bunch of information.
What I am doing is when the user opens the app, I pull this data out of the database, process it using the display options set by the user (Like change the string formats, time formats, date formats, number decimals etc), and then put it in ListFragment which using my own implementation of ArrayAdapter. User can of course change the preferences in the middle of the session, where I reload the data and reformat it and present it to the user. The user can click on an item in the list, and see more details of that item. I accomplish this by overriding ListFragment.onListItemClick().
I have been reading about SimpleCursorAdapter. I am confused if the use of this would be more correct than using an ArrayAdapter for what I am doing. I am confused because I am not directly mapping the database data to the view. So should I be using a SimpleCursorAdapter? Also, the _ID column seems to be a requirement. I don't want to rename my table at this point. After a few articles and tutorials, I am not sure what to do. So any suggestions are appreciated.

Select multiple object type with auto complete

I am looking for some help to find a powerfull way to allow selection of different List items.
My case is that i have for exemple a List profiles, List teams ... and i'd like to have an autocomplete input that will show, for exemple if i type Al, all Teams and Profiles objects having there member variable name begining by Al.
The result would be that i could get from the activity, on submit click performed, a List & a List containing all the objects who have been selected through the autocomplete form.
Also i'd like that the list offered to the user that match the chars he typed show the name and a picture (facebook like tag selection).
Obviously i am not asking for some code but at least some guidelines from experienced Android devs who know what to do and not to do to create this kind of thing.
Thanks
Loader are one of the best way to filter list. You init a loader which take the String constraint used for filter, the each time the user type, you update the constraint and restart your Loader.
If I suppose that all your object are cached in a SQLite database you can use a CursorAdapter, Cursor and CursorLoader.
You create the needed CursorLoader by filter the query with the content of the EditText.
If you're not familiar with CursorLoader there is the AsyncTaskLoader, with this you won't have the need of DB and to code a provider which can accept raw query. Your object in ListA, ListB, etc must inherits of common class (hum... DataThing maybe :-)), you concatenate the objects in a list then you can filter the list : What is the best way to filter a Java Collection?
That's for the data filtering. Now in order to display the data the way you want, you can display of list below the EditText field or create a custom component if you want a more advanced look.

Android AutoCompleteTextView suggestion if nothing is found

I am making a point of sale app for Android, and I have a AutoCompleteTextView loaded in with the database of items that they can buy, but I also want the AutoCompleteTextView to double as a way to add custom items/notes into the order.
So for example, the customer is ordering Steak, but doesnt want any seasoning. My database includes options for 'No Onions' 'No Mushrooms', etc, but not 'No Seasoning', and if the waiter types in 'No Seasoning' into the AutoCompleteTextView, I want a suggestion 'Add as Note' to pop up.
Is there a way to add this suggestion when no other suggestions are found, either by making it always on the dropdown list (making it not able to be filtered out), or by detecting when no items are on the dropdown list and adding it in then?
I think this can be done using MatrixCursor.
When you retrieve the cursor from your database, check if its empty with Cursor.moveToFirst(). Then either fill the MatrixCursor with your database cursor or a single "Add as Note" item if empty.
I use this to combine two database Cursor in one for suggestions here (method getUrlSuggestions(), the last one). Note that this example is not very clean, as all values are casted to String before insertion in the MatrixCursor. This is not necessary as the addRow() method take an array of Object.

Retrieving Database Information and Showing in ListView with Android

I am working on an Android app that will allow the user to see restaurants in the city I live in. I am storing each restaurants information (name, address, telephone, hours, category, website) in an SQLite database.
What I am trying to do is to create a SortByAlpha activity that will list the restaurants by name in alphetically-descending order.
I understand that I should be using a Cursor to do this but I can't find a half decent tutorial, all of the "tutorials" I find are a bunch of code with minimal explanation. How can I do this / Where can I find a good tutorial?
Use SimpleCursorAdapter, which bridges between Cursor and Adapter. Here is an example how to use it: http://developer.android.com/guide/topics/ui/binding.html
I would advise creating a "Restaurant" class that contains all the fields you will be listing. Then make your SQL call and specify "ORDER BY Name". Then create an ArrayList that can be fed to your custom list adapter! Also, if they were to somehow get out of order, just implement the "Comparable" interface for the Restaurant class and compare based on "Name" and then you can call Collections.sort(restaurantlist); to sort them in alphabetical order. I personally think ORDER BY is the easier way to go!

Autocomplete list from SQLite with criteria

Can someone point me to right direction, how to create an adapter for AutoCompleteTextView, which would be getting data from SQLite DB, using data, which user entered into the text field? I want to use the user-entered data to filter suggestions for autocompletion. I imagine that adapter should always take user-entered data as soon as changes appears and use it for fetching suggestions on-the-fly. Is that possible? So far I've seen many tutorials for autocompletion where static String arrays were used, but never seen them build dynamically. Is it possible to do it automatically or I need always fetch String array myself and pass as ArrayList to adapter on every AutoCompleteTextView change?
You might be looking for CursorAdapter. Use it just like an ArrayAdapter, but instead of feeding it with an ArrayList, provide a database Cursor. Google for CursorAdapter and you should get a lot more example codes.

Categories

Resources