Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Section Indexer Overlay is not updating as the adapter's data changes

Tags:

android

I have implemented Section Indexer for an Adapter class which extends BaseAdapter. Now for the first launch Section Indexer is showing an overlay correctly. But when the contents of the list gets updated the Section Overlay does not get updated and gives ArrayOutOfBoundException. For one fix what i did is i made listview.setFastScrollEnabled(false); update the adapter contents; and then listview.setFastScrollEnabled(true); Now what happens is overlay gets updated but the Overlay is coming to the left top of the listview. How can I fix this.

like image 242
Shrikanth Kalluraya Avatar asked May 26 '10 10:05

Shrikanth Kalluraya


1 Answers

Thought I'd share a ready-made version of the above workaround for a ListActivity:

private boolean FLAG_THUMB_PLUS = false;
private void jiggleWidth() {

    ListView view = getListView();
    if (view.getWidth() <= 0)
        return;

    int newWidth = FLAG_THUMB_PLUS ? view.getWidth() - 1 : view.getWidth() + 1;
    ViewGroup.LayoutParams params = view.getLayoutParams();
    params.width = newWidth;
    view.setLayoutParams( params );

    FLAG_THUMB_PLUS = !FLAG_THUMB_PLUS;
}

Works for me.

like image 86
Mikael_S Avatar answered Oct 24 '22 20:10

Mikael_S