How to create an alphabetical scrollbar displaying all the letter in android?

时光怂恿深爱的人放手 提交于 2019-11-27 05:55:44
FunkTheMonk

This is an iPhone feature, Android uses fast scroll. I'd recommend that you use the platform alternative rather than try to enforce common functionality.

If you must, you'll have to implement this yourself. Put your list view in a RelativeLayout and put A-Z TextViews in a vertical LinearLayout that is set to layout_alignParentRight="true". Set the TextView's tag to A-Z appropiately and set onClick="quickScroll" on all of them.

Implement in your Activity:

public void quickScroll(View v) {
    String alphabet = (String)v.getTag();
    //find the index of the separator row view
    list.setSelectionFromTop(index, 0);
}

This will scroll to the selected letter onClick, but I believe you can scroll your finger over the alphabet on iPhone and it'll update the list? You'll have to implement an onTouchListener rather than onClickListener for that.

You can try using IndexScroller which only visible on touch and auto invisible when no contact. Here is the screenshot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!