Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A little bug! if the listview have a headerview ,onItemClick give a wrong position value ! #26

Open
zzhangxiaoyun opened this issue Nov 18, 2014 · 2 comments

Comments

@zzhangxiaoyun
Copy link

No description provided.

@zzhangxiaoyun
Copy link
Author

public void setOnItemClickListener(final PinnedHeaderListView.OnItemClickListener listener) {
    super.setOnItemClickListener(new android.widget.ListView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int rawPosition, long id) {
            PinnedBaseAdapter adapter;
            if (adapterView.getAdapter().getClass().equals(HeaderViewListAdapter.class)) {
                HeaderViewListAdapter wrapperAdapter = (HeaderViewListAdapter) adapterView.getAdapter();
                adapter = (PinnedBaseAdapter) wrapperAdapter.getWrappedAdapter();
            } else {
                adapter = (PinnedBaseAdapter) adapterView.getAdapter();
            }
            rawPosition = rawPosition - getHeaderViewsCount();
            if (rawPosition < 0||rawPosition >= adapter.getCount())//if have headerViews or FooterViews They didn't click event
                return;
            int section = adapter.getSectionForPosition(rawPosition);
            int position = adapter.getPositionInSectionForPosition(rawPosition);

            if (position == -1) {
                listener.onSectionClick(adapterView, view, section, id);
            } else {
                listener.onItemClick(adapterView, view, section, position, id);
            }
        }
    });
}

@ma-jahn
Copy link

ma-jahn commented Mar 11, 2016

You saved my day. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants