sergejsha / pinned-section-listview

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

Wrong View is passed to Adapter's getView if there are 2 pinned View types #73

Open farmazon3000 opened 9 years ago

farmazon3000 commented 9 years ago

From time to time I'm getting wrong View as convertView in getView

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

I have 3 View types set: 2 of them are pinned SECTION_1 and SECTION_2 and 1 is ITEM

    @Override
    public int getViewTypeCount() {
        return 3;
    }

    @Override
    public int getItemViewType(int position) {
        return getItem(position).getType();
    }

    @Override
    public boolean isItemViewTypePinned(int viewType) {
        return viewType != ITEM;
    }

The Views for SECTION_1 and SECTION_2 are mixed up from time to time

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(null == convertView){
            if(ITEM == getItemViewType(position)){
                convertView = inflater.inflate(R.layout.circle_item, parent, false);
            }
            else if(SECTION_1 == getItemViewType(position)){
                convertView = inflater.inflate(R.layout.section_1, parent, false);
            }
            else if(SECTION_2 == getItemViewType(position)){
                convertView = inflater.inflate(R.layout.section_2, parent, false);
            }
        }
        else{
            if(ITEM == getItemViewType(position)){
                if(null == convertView.findViewById(R.id.item_element)){
                    Log.i(TAG, "ITEM not appropriate View");
                }
            }
            else if(SECTION_1 == getItemViewType(position)){
                if(null == convertView.findViewById(R.id.section_1_element)){
                    Log.i(TAG, "SECTION_1 not appropriate View");
                }
            }
            else if(SECTION_2 == getItemViewType(position)){
                if(null == convertView.findViewById(R.id.section_2_element)){
                    Log.i(TAG, "SECTION_2 not appropriate View");
                }
            }
        }

        return convertView;
    }
miroslavign commented 8 years ago

Any info about this one. Integrating this lib in a cursor adapter is fairly simple, but this issue is really annoying, and I can not get to the bottom of it.

Just a note, I am using it in a CursorAdapter class ...CursorAdapter implements SectionIndexer, PinnedSectionListView.PinnedSectionListAdapter