Tuesday, June 26, 2012

Android : ListView with fast scroll using alphabets in the right side of the screen


Android ListView with fast scroll using alphabets in the right side of the screen

We have lot of questions like
Alphabetical sorted listview with Alphabetic section using Adapter in Android application.
Listview alphabetical index programmatically
In IPhone we are having Indexed UITableView
Android Listview like iphone contacts list (alphabets in right side of the list)

We are not having similar functionality in android but we are having android:fastScrollEnabled and alphaIndexer.
Without using android:fastScrollEnabled and alphaIndexer. Just with touch recognition, alphabetically sorting can be achieved easily.

If you want to implement the same feature in android and solution for all the above questions, we can try this approach

Code: indexTableCode

Screen Shot:





















Thanks for reading :)
If you have any other quick thoughts/hints that you think people will find useful, feel free to leave a comment.

29 comments :

  1. Thanks Vardhan,you have helped a lot.

    ReplyDelete
  2. hi vardhan thanks for the tutorial i t hlped me lot
    check out the android app we have just released https://play.google.com/store/apps/details?id=com.smartappgenerator.dailyquiz

    ReplyDelete
  3. you have helped a lot..how to get onItemClickListener in our example.

    ReplyDelete
    Replies
    1. Updated Code is added.
      Have onclick listener to the linearlayout in getView method.

      Delete
    2. thanks, same code with sticky headers will be awesome https://github.com/emilsjolander/StickyListHeaders

      Delete
  4. Hello vardhan,

    Thank you for your tutorial

    I want to use your solution but with Fragment.

    After making transformation to replace Activity by Fragment , I am getting blank screen.

    Please help.

    Fred

    ReplyDelete
    Replies
    1. Hi Fred,
      I haven't tried anytime with fragment.
      Let me give it a try.

      Thanks & Regards
      Harsha

      Delete
  5. Hey Vardhan thanks for this example, very usefull, how should I do for showing in bold the letter which I've selected?

    Thanks.

    ReplyDelete
  6. hi vardhan , i m not able to download ur demo project.plz help

    ReplyDelete
    Replies
    1. https://sites.google.com/site/vardhanexp/-site-vardhanexp-indextablecode/IndexTable.zip?attredirects=0&d=1

      Govind, link is working, You can check with above link

      Delete
  7. I want to open a new activity on click of a list item pls help its urg....i have tried it from you userlistadapter click listener but no luck?????

    ReplyDelete
    Replies
    1. You can call other activity in onClickListener.
      Check out this link : https://sites.google.com/site/vardhanexp/-site-vardhanexp-indextablecode/IndexTable.zip?attredirects=0&d=1

      Delete
  8. Hello Vardhan Thanks for your post its a really nice tutorial i just want to know that if u want to show selected list as highlight like in contact of phone than what you will do.

    ReplyDelete
    Replies
    1. Hi Agarwal,
      I have shared source code, just have a look of it. :)

      Delete
  9. Hello Vardhan. Excellent app. I am just getting started with Android programming and am having difficulty figuring out where and how to modify to import from a database instead of the Book list you have. If you could point me in the right direction I would appreciated it.
    Thank you,
    Jeffery

    ReplyDelete
    Replies
    1. Dear Jeffery,

      Customize getUserList method from UserService class according to your needs, we can retrieve cursor object from database and convert cursor object to List of Book Object

      Hope above information helps you. If your facing any difficulties I can help you.

      ALL THE BEST

      Regards
      Harsha

      Delete
  10. Dear Vardhan,

    I modified ur getUserList method in UserService but i can not fetch contact in that class.
    Please help me...

    ReplyDelete
    Replies
    1. Dear Murugan,

      Push the source code from the post, you can see the changes.

      Regards
      Vardhan
      Harsha

      Delete
  11. Vardhan,
    Thanks for the help, got the DB working to populate the list. One other issue that I am not sure where to modify. When one of the fields begins with a lower case such as "eBay" it creates a new section at the end of all the CAPS and adds an "e" to the bottom of the alphabet side bar. Not sure where both of these are handled.
    Thanks,
    Jeffery

    ReplyDelete
    Replies
    1. Dear Jeffery,

      Its handled at 2 places.
      Sort technique in Book and CustomListIndex classes.

      I have modified my source code as per your requirement please have look:
      https://sites.google.com/site/vardhanexp/-site-vardhanexp-indextablecode/IndexTable.zip?attredirects=0&d=1

      Regards
      Harsha

      Delete
  12. Harsha,
    Thanks, worked great. I just added in to make the alphabet letter uppercase if it is lower the first time added. Also, if the main list is empty I had to error trap for the "tmpIndexListSize" in the CustomListIndex to avoid an error. Once again thanks for the help.
    Jeffery

    ReplyDelete
  13. Thanks Vardhan, beautiful code.

    ReplyDelete
  14. Harsha,
    All is working well. Just noticed that of the Book Title is only one character, it has an issue. could you point me where to investigate this for a fix?
    thanks,
    Jeffery

    ReplyDelete
  15. very good blog it helped me lot , Thanks sir

    ReplyDelete
  16. I need help about alphaindexer in this tutorial. Please upload as may RoboGuice tutorials as possible.

    ReplyDelete
    Replies
    1. Yes Surendra, what help do u required?

      Delete