如何在Listview android中添加第一个字母位于右垂直位置的字母分段索引器

如何在Listview android中添加第一个字母位于右垂直位置的字母分段索引器,android,list,android-layout,Android,List,Android Layout,我正在创建一个应用程序,在这个应用程序中,我必须以字母顺序显示listView,并在右竖条中显示字母表的第一个字母,如屏幕截图所示。 所以,请帮助我如何创建listView与字母部分索引与索引在右角 谢谢您可以在github上搜索开放库 您可以使用的LIB之一:Daniel Nam的IndexableListView 您可以使用它,因为它是通过查看源代码来获得想法;) 好运将来可能会帮助别人。要做到这一点,你可以做两件事。首先创建一个可展开的列表视图,该视图将显示项目的活动列表,其中包含a到Z

我正在创建一个应用程序,在这个应用程序中,我必须以字母顺序显示listView,并在右竖条中显示字母表的第一个字母,如屏幕截图所示。 所以,请帮助我如何创建listView与字母部分索引与索引在右角


谢谢

您可以在github上搜索开放库

您可以使用的LIB之一:Daniel Nam的IndexableListView

您可以使用它,因为它是通过查看源代码来获得想法;)


好运将来可能会帮助别人。要做到这一点,你可以做两件事。首先创建一个可展开的列表视图,该视图将显示项目的活动列表,其中包含a到Z列表的部分,请参考此示例

下一步是向其添加节索引器。下面的链接适用于listview

这将在区段索引器中将可展开列表视图的滚动位置设置为一个用户触摸

private static String sections = "abcdefghilmnopqrstuvz";

this.setSelection(((SectionIndexer) getAdapter()) .getPositionForSection(currentPosition));//position of group view item 
现在,在getPositionForSection回调方法中返回头的位置

@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;
}
@Override public int getPositionForSection(int sectionIndex){
//获取组的总数
对于(int i=0;i=0;j--){
//如果是字母B,则前一组项目即A包含3个孩子
//这笔钱维持不变
childCount=childCount+this.getChildrenCount(j);
}
//对于组项目B,i=0,childCount为3,依此类推
返回i+childCount;
}
}
}
返回0;
}
剩下的,在例子中解释的同样的逻辑应该像魅力一样对你有用

参考此链接参考此链接