I am creating an app where i have to show listView with alphabetical sections and first letter of alphabet in right vertical bar as shown in screen shot. so please assist me to how to create listView with alphabetical section indexer with index at right corner.
thanks
You can search for open libs on github.
One of the libs you can use : IndexableListView by Daniel Nam
https://github.com/woozzu/IndexableListView
You can use it as it is of get the idea by taking a look at the source code ;)
good luck
Might help someone in future. There is two things you can do to achieve this. First create a expandable List view which will display the live of items with sections for a list of A to Z, refer this as example http://javapapers.com/android/android-expandable-listview .
Next step is add section indexer to it. Link below works with listview http://www.survivingwithandroid.com/2012/12/android-listview-sectionindexer-fastscroll.html .
This will set your scroll position of expandable listview to one user touches in Section Indexer.
private static String sections = "abcdefghilmnopqrstuvz";
this.setSelection(((SectionIndexer) getAdapter()) .getPositionForSection(currentPosition));//position of group view item
Now inside getPositionForSection callback method return the position of header
@Override public int getPositionForSection(int sectionIndex) {
// Get the total number of groups
for (int i = 0; i < this.getGroupCount(); i++) {
//Get Group Item like,For 0 Group Item A,For 1 Group Item B etc
String groupItem = (String) this.getGroup(i);
int childCount = 0;
//Start Matching for letter B on section indexer, get the count of child
//for letter A and same logic for other letters
if (groupItem.charAt(0) == sections.charAt(sectionIndex)){
int previousChildIndex = i - 1;
//Run a for loop to get previous childs
for (int j = previousChildIndex; j >= 0; j--) {
//If for letter B, previous group Item i.e.A contains 3 childs
//the sum is maintained
childCount = childCount + this.getChildrenCount(j);
}
//for Group Item B, i=0 and childCount is 3 and so on
return i + childCount;
}
}
}
return 0;
}
Rest the same logic explained in example should work for you like a charm!!!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.