Implemented Android AlphabetIndexer but it's not showing -


i have followed few stackoverflow threads, tutorials , can gather documentation can't aplhabetindexer working in android. goal have indexed listview users can scroll using letters on right per standard contacts app on phone. i'll add section headers in list , make filterable user types want basic list working.

i can load list , results cursor, never letters appear on right of listview. i've tried different combinations of setting adapter, including in oncreateview null cursor , calling changecursor(cursor) in onloadfinished() callback, current version below sets adapter in onloadfinished() callback.

has got full working version of setup , adapter code share? preferably using method of creating adapter first, calling changecursor(cursor) in onloadfinished() callback.

what have far:

storelistadapter.java

public class storelistadapter extends simplecursoradapter implements sectionindexer {  private alphabetindexer malphabetindexer;  public storelistadapter(context context, int layout, cursor cursor, string[] from, int[] to, int flags) {     super(context, layout, cursor, from, to, flags);     if(cursor != null){         malphabetindexer = new alphabetindexer(cursor,                 cursor.getcolumnindex(storeentry.table_alias + storeentry.column_name),                 "abcdefghijklmnopqrtsuvwxyz");         malphabetindexer.setcursor(cursor);     } }  @override public void changecursor(cursor cursor) {     super.changecursor(cursor);     if(cursor != null){         malphabetindexer = new alphabetindexer(cursor,                 cursor.getcolumnindex(storeentry.table_alias + storeentry.column_name),                 "abcdefghijklmnopqrtsuvwxyz");         malphabetindexer.setcursor(cursor);     } }  @override public object[] getsections() {     if(malphabetindexer != null){         return malphabetindexer.getsections();     }else{         return null;     }  }  @override public int getpositionforsection(int sectionindex) {     if(malphabetindexer != null){         return malphabetindexer.getpositionforsection(sectionindex);     }else{         return 0;     }  }  @override public int getsectionforposition(int position) {     if(malphabetindexer != null){         return malphabetindexer.getsectionforposition(position);     }else{         return 0;     } }  } 

storelistfragment.java

public class storelistfragment extends fragment implements loadermanager.loadercallbacks<cursor> {  private listview mlistview; private storelistadapter madapter;  public static storelistfragment newinstance() {     storelistfragment fragment = new storelistfragment();     return fragment; }  /**  * mandatory empty constructor fragment manager instantiate  * fragment (e.g. upon screen orientation changes).  */ public storelistfragment() { }  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     getloadermanager().initloader(0, null, this); }  @nullable @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {     view view = inflater.inflate(r.layout.fragment_store_search, container, false);     mlistview = (listview) view.findviewbyid(r.id.search_result_list);     return view; }  @override public void onattach(activity activity) {     super.onattach(activity);  }  @override public void ondetach() {     super.ondetach(); }  @override public loader<cursor> oncreateloader(int id, bundle args) {     return new cursorloader(             getactivity(),   // parent activity context             storeprovider.content_uri,        // table query             null,     // projection return             null,            // no selection clause             new string[]{getstring(r.string.centre_id)},            // no selection arguments             null             // default sort order     ); }  @override public void onloadfinished(loader<cursor> loader, cursor data) {     mlistview.setfastscrollenabled(true);     mlistview.setscrollingcacheenabled(true);     madapter = new storelistadapter(getactivity().getapplicationcontext(), r.layout.store_list_item, data, new             string[]{storeentry.table_alias + storeentry.column_name}, new int[]{r.id.item_name}, cursoradapter.flag_register_content_observer);     mlistview.setadapter(madapter); }  @override public void onloaderreset(loader<cursor> loader) {     madapter.changecursor(null); } } 

the exact behavior can found in class fastscroller helper class abslistview. there piece of code there decides if "the list long"

final boolean longlist = childcount > 0 && itemcount / childcount >= min_pages; 

min_pages defined value of 4. there have it, if list item count not @ least 4x child count (visible rows) fast scroller , alphabet indexer not appear.


Comments