3

スクリーンショットに示すように、アルファベットセクションとアルファベットの最初の文字を右側の垂直バーに表示する必要があるアプリを作成しています。右隅にインデックスがあるアルファベット順のセクションインデクサーを使用してlistViewを作成する方法を教えてください。

ありがとう

4

2 に答える 2

0

将来誰かを助けるかもしれません。これを実現するためにできることは 2 つあります。最初に、A から Z までのリストのセクションを含むアイテムのライブを表示する展開可能なリスト ビューを作成します。これをhttp://javapapers.com/android/android-expandable-listviewの例として参照してください。

次のステップは、セクション インデクサーを追加することです。以下のリンクはリストビューhttp://www.survivingwithandroid.com/2012/12/android-listview-sectionindexer-fastscroll.htmlで動作します。

これにより、展開可能なリストビューのスクロール位置が、セクション インデクサーで 1 人のユーザーがタッチした位置に設定されます。

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;
}

残りの例で説明されているのと同じロジックが魅力のように機能するはずです!!!

于 2015-03-30T10:27:41.307 に答える