Open zzhangxiaoyun opened 9 years ago
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); } } }); }
You saved my day. Thanks!