views:

30

answers:

1

Hi, In android there is A to Z selector on right side of the contacts. one can just select on of the alphabet and only those contacts will be displayed which are starting with that selected alphabet. I want to implement such kind of list.. !! Any idea ??

A: 

Here's the basic idea of what you'd need to do:

First you'll want to generate your alphabet list... you can either hard code this (Always showing A-Z) or you can try running a query from the database that will give you all of the display names, parsing the cursor to build a list of unique letters (only add a letter if its not in your list already).

After getting your list of characters you'll want to assign them to widget of your choice (either a container view with buttons or some kind of listview would work). Make sure to also have some kind of list for your contacts to be displayed in as well.

When responding to a click event of one of your letters, you'll want to run a query against the contacts database that adds something similar the following LIKE clause to your where string:

" substr(, 1,1) LIKE '%' "

The resulting data you then just need to display in your data list.

Good luck :)

Marloke
But the problem is, all those list items are coming from server side, what i can do is, i can store all those items to database temporarily. Isn't that control we can call as intent by setting adapter or something like that ??
Hrushikesh
Are we still talking about the contacts database? The contacts database is also located on the device itself, not some external server (though it does sync with google). If you use a cursor with the query results you can still modify the data before displaying it. If you want to create your own local database or data object to offload the results into, you can. I don't see a particular benefit to doing so though.
Marloke