sergejsha / pinned-section-listview

Easy to use ListView with pinned sections for Android.
2.59k stars 808 forks source link

PinnedShadow is not recreated when notifyDataSet changed. #16

Closed chrisjenx closed 11 years ago

chrisjenx commented 11 years ago

I added the data set observer in my code.

But if you change the dataset after the adpater has been attached, then the listview does not recreate the pinned view.

If you need the code I can do a pull request later.

Something like:

/**
     * Recreate the pinned view on change/invalidated.
     */
    private class AdapterDataSetObserver extends DataSetObserver{
        @Override
        public void onChanged() {
            super.onChanged();
            destroyPinnedShadow();
        }

        @Override
        public void onInvalidated() {
            super.onInvalidated();
            destroyPinnedShadow();
        }
    }

worked a charm for me

sergejsha commented 11 years ago

Thanks for reporting and offering a solution. I pushed a fix. Does it work for you?

chrisjenx commented 11 years ago

My setAdapter is different, but yours does effectively the same thing.

@Override
    public void setAdapter(ListAdapter adapter) {
        if (mAdapter != null && mDataSetObserver != null) {
            mAdapter.unregisterDataSetObserver(mDataSetObserver);
        }

        if (BuildConfig.DEBUG && adapter != null) { // assert adapter in debug mode
            if (!(adapter instanceof PinnedSectionListAdapter))
                throw new IllegalArgumentException("Does your adapter implement PinnedSectionListAdapter?");
            if (adapter.getViewTypeCount() < 2)
                throw new IllegalArgumentException("Does your adapter handle at least two types of views - items and sections?");
        }

        destroyPinnedShadow();
        super.setAdapter(adapter);

        if (adapter != null) {
            mAdapter = adapter;
            mDataSetObserver = new AdapterDataSetObserver();
            mAdapter.registerDataSetObserver(mDataSetObserver);
        }

    }

This follows how the current ListView impliments the observer