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

Wrong section & position in onSectionClick/onItemClick #13

Open
michalciolek opened this issue May 20, 2013 · 1 comment
Open

Wrong section & position in onSectionClick/onItemClick #13

michalciolek opened this issue May 20, 2013 · 1 comment

Comments

@michalciolek
Copy link

When I add a header to the ListView by code e.g:
PinnedHeaderListView listView = (PinnedHeaderListView) view.findViewById(R.id.pinnedListView); LinearLayout header1 = (LinearLayout) inflater.inflate(R.layout.menu_left_header_profile, null); listView.addHeaderView(header1);

the position / section in onSectionClick/onItemClick is invalid....

In PinnedHeaderListView.OnItemClickListener you do not take into account the numbers of headers added to the ListView

rawPosition in public void onItemClick(AdapterView<?> adapterView, View view, int rawPosition, long id) contains the number of rows and headers.

I fix it by add line:

rawPosition -= ((ListView) adapterView).getHeaderViewsCount();

in:

public static abstract class OnItemClickListener implements AdapterView.OnItemClickListener {
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int rawPosition, long id) {
        SectionedBaseAdapter adapter;
        if (adapterView.getAdapter().getClass().equals(HeaderViewListAdapter.class)) {
            HeaderViewListAdapter wrapperAdapter = (HeaderViewListAdapter) adapterView.getAdapter();
            adapter = (SectionedBaseAdapter) wrapperAdapter.getWrappedAdapter();
        } else {
            adapter = (SectionedBaseAdapter) adapterView.getAdapter();
        }

        rawPosition -= ((ListView) adapterView).getHeaderViewsCount();

        int section = adapter.getSectionForPosition(rawPosition);
        int position = adapter.getPositionInSectionForPosition(rawPosition);

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

    public abstract void onItemClick(AdapterView<?> adapterView, View view, int section, int position, long id);

    public abstract void onSectionClick(AdapterView<?> adapterView, View view, int section, long id);

}
@superbool
Copy link

Thank you very much

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