TonicArtos / StickyGridHeaders

This project has been superseded by SuperSLiM, a layout manager for RecyclerView. I strongly recommend using SuperSLiM and not StickyGridHeaders.
http://tonicartos.com
Apache License 2.0
1.47k stars 441 forks source link

getPositionForView works wrong? #97

Closed Lingviston closed 6 years ago

Lingviston commented 10 years ago

I have buttons in cells of my StickyGridHeadersGridView. I externally setup listners for those buttons from my Activity. In each listener I use StickyGridHeadersGridView.getPositionForView method to detect which item this button is associated. Everything works fine until I implement StickyGridHeadersSimpleAdapter in my adapter. After that getPositionForView returns wrong value (I have 3 columns and only 1 header, value is greater then real by 3). Maybe this is correct behavior from some point but I need to be able to get view position related to the dataset like in simple GridView or ListView.

Lingviston commented 10 years ago

I understand how to get position related to dataset correctly but I at least need to know number of headers before view/position which I can't get from StickyGridHeadersGridView.

tolbkni commented 10 years ago

I think you can create a interface like this:

public interface ButtonOnClickListener {
    public OnClick(Button button, int position)

then in the CustomAdapter, pass interface implementation to it's constructor as a argument. And set listener for the buttons in the getView() function like this:

public View getView(final int position, View convertView, ViewGroup parent) {
    ...
    button.setOnClickListener(new View.OnClickListener() {
        mButtonOnClickListener.OnClick(button, position);
    }
    ...
}
Lingviston commented 10 years ago

Of caurse this is a solution but I want to have listeners inside Activity not Adapter. For example to achieve this I can also set position as Tag for my Button.

Lingviston commented 10 years ago

Found the solution. After receiving position I don't request item from my Adapter using it but call getAdapter() method of StickyGridHeadersGridView and use it's getItem() method.