我正在尝试在 ExpandableListView 中启用快速滚动,并且我已经尝试了此链接中的解决方法:android fastScroll 仅涵盖列表的一部分
问题是,每当我展开足够多的组以触发快速滚动条时,它都会给我 NullPointerException 错误。我试过以下代码:
MainActivity:
expandblelist = (ExpandableListView) findViewById(R.id.mexpandablelistview);
Adapter = new Adapter(this, expandblelist, category_array);
expandblelist.setAdapter(Adapter);
expandblelist.setFastScrollEnabled(true);
Adapter:
public class Adapter extends BaseExpandableListAdapter
implements SectionIndexer, AbsListView.OnScrollListener {
private Context mContext;
private ExpandableListView mExpandableListView;
private List<Category> mGroupCollection;
private int[] groupStatus;
private boolean manualScroll;
private String[] groups;
public Adapter(Context context, ExpandableListView pExpandableListView, List<Category> pGroupCollection) {
mContext = context;
mGroupCollection = pGroupCollection;
mExpandableListView = pExpandableListView;
groupStatus = new int[mGroupCollection.size()];
setListEvent();
this.mExpandableListView.setOnScrollListener(this);
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
this.manualScroll = scrollState == SCROLL_STATE_TOUCH_SCROLL;
}
@Override
public void onScroll(AbsListView view,
int firstVisibleItem,
int visibleItemCount,
int totalItemCount) {}
@Override
public int getPositionForSection(int section) {
if (manualScroll) {
return section;
} else {
return mExpandableListView.getFlatListPosition(ExpandableListView.getPackedPositionForGroup(section));
}
}
// Gets called when scrolling the list manually
@Override
public int getSectionForPosition(int position) {
return ExpandableListView.getPackedPositionGroup(mExpandableListView.getExpandableListPosition(position));
}
@Override
public String[] getSections() {
return groups;
}
LogCat:
NullPointerException
FastScroller.getThumbPositionForListPosition(FastScroller.java:680)
FastScroller.onScroll(FastScroller.java:487)
at android.widget.AbsListView.invokeOnItemScrollListener(AbsListView.java:1337)
有人可以指导我吗?我非常感谢您的时间和帮助。
非常感谢