android - AlphabetIndexer.getSectionForPosition() Always Returns 0 -


i trying make letters appear when fast scrolling on listview. reason, letter appears first letter in alphabet (a space). appears getsectionforposition() returns 0, though should not. below code:

activity_host.xml

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:paddingbottom="@dimen/activity_vertical_margin"     android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     tools:context=".hostactivity" >     <listview android:id="@+id/song_list"          android:layout_width="fill_parent"          android:layout_height="fill_parent"         android:fastscrollenabled="true" /> </relativelayout> 

hostactivity.java

public class hostactivity extends activity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_host);          loadsongs();     }      private void loadsongs() {         uri songsuri = mediastore.audio.media.external_content_uri;         string[] projection = songcursoradapter.song_columns;         string songfilter = mediastore.audio.media.is_music + " != 0";         string orderby = songcursoradapter.ordered_by;         cursor songcursor = new cursorloader(this, songsuri, projection, songfilter, null, orderby).loadinbackground();          songcursoradapter songsadapter = new songcursoradapter(this, songcursor, 0);         listview songview = (listview) this.findviewbyid(r.id.song_list);         songview.setadapter(songsadapter);     } } 

songcursoradapter.java

class songcursoradapter extends cursoradapter implements sectionindexer {     public final static string[] song_columns = { mediastore.audio.media._id, mediastore.audio.media.title, mediastore.audio.media.title_key, mediastore.audio.media.data };     public final static string ordered_by = mediastore.audio.media.default_sort_order;      private context context;     private alphabetindexer indexer;      songcursoradapter(context context, cursor c, boolean autorequery) {         super(context, c, autorequery);         this.context = context;          setupindexer(c);     }      songcursoradapter(context context, cursor c, int flags) {         super(context, c, flags);         this.context = context;          setupindexer(c);     }      private void setupindexer(cursor c) {         int sortedbycolumn = c.getcolumnindexorthrow(ordered_by);         string alphabet = " abcdefghijklmnopqrstuvwxyz";     indexer = new alphabetindexer(c, sortedbycolumn, alphabet);     }      @override     public void bindview(view view, context context, cursor cursor) {         // code irrelevant     }      @override     public view newview(context context, cursor cursor, viewgroup parent) {         view view = layoutinflater.from(context).inflate(r.layout.song_layout, null);         return view;     }      @override     public cursor swapcursor(cursor c) {         if (c != null) {             setupindexer(c);         }         return super.swapcursor(c);     }      @override     public int getpositionforsection(int section) {         return indexer.getpositionforsection(section);     }      @override     public int getsectionforposition(int position) {         return indexer.getsectionforposition(position);     }      @override     public object[] getsections() {         return indexer.getsections();     } } 

edit: no letters appearing @ now. navigation bar behaves oddly, though. every time scroll down, jumps top.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -