Closed Lingviston closed 6 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.
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);
}
...
}
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.
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.
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.