DynamicGrid icon indicating copy to clipboard operation
DynamicGrid copied to clipboard

getViewForId() Often returns null

Open ZacSweers opened this issue 11 years ago • 3 comments

I don't really know what else I can say about this. It seems the library can't find a view at times, and causes random NPE crashes internally when it happens because callers of getViewForId() always assume the result is not null. This library doesn't seem to be under development anymore either, so posting this in the hopes that someone else has run into this and found a cause/solution.

I believe this is part of a deeper problem, as it seems #46, #8, and #36 are all possibly related.

ZacSweers avatar Jan 28 '15 23:01 ZacSweers

Update: I think my coworker solved the problem in #58. This at least covers the issues we've seen with this in the past.

ZacSweers avatar Jan 31 '15 02:01 ZacSweers

I found that it would not crash if the layout_height of DynamicGridView was set wrap_content.

JingHaifeng avatar Aug 13 '15 09:08 JingHaifeng

Finally,I found the error method:

private Point getColumnAndRowForView(View view) {
    int pos = getPositionForView(view);
    int columns = getColumnCount();
    int column = pos % columns;
    int row = pos / columns;
    return new Point(column, row);
}

Modify: pos = getPositionForView(view) - getFirstVisiblePosition();

Everything is fine.

JingHaifeng avatar Aug 13 '15 11:08 JingHaifeng