grid-with-header-list-adapter icon indicating copy to clipboard operation
grid-with-header-list-adapter copied to clipboard

Last view on odd numbers do not work

Open plattysoft opened this issue 10 years ago • 2 comments

If you inflate the view using the parent view (and false), and you have not enough rows to require scroll, the last view is not properly displayed (0 height)

It does not happen if you inflate the view with a null parent.

http://stackoverflow.com/questions/24987801/listasgridbaseadapter-only-displays-grid-items-when-there-are-even-number-of-ite

plattysoft avatar Jul 28 '14 11:07 plattysoft

I'm not sure if this is related, but I found a bug where getItemView() is called for one of the filler views (the ones created to fill gaps in rows with odd item counts) because of view recycling. Sometimes when getView() is called for a full row, a view that contains filler views is passed in as the view parameter.

I fixed it by catering for two view types in the adapter (one for full rows and one for the last row with filler views):

@Override public int getViewTypeCount() {
    // Not necessary for only 1 column
    if (getNumColumns() == 1) return 1;

    return 2;
}

@Override public int getItemViewType(int position) {
    if (getNumColumns() == 1) return 0;

    // If we have an odd item count and this is the last row, use the view type with filler views
    if (getItemCount() % 2 != 0 && position == getCount() - 1) {
        return 1;
    }

    return 0;
}

IIRC, after implementing this fix I didn't get this 0 height issue anymore either.

HenriLangenhoven avatar Dec 03 '14 07:12 HenriLangenhoven

Oh, that's interesting.

I did not had that problem, but I can imaging it happening on specific version of the OS.

Can you make a pull request?

plattysoft avatar Dec 03 '14 12:12 plattysoft