我試圖啓用ExpandableListView快速滾動,我已經試過此鏈接中的解決方法解決:android fastScroll only covers part of the list如何讓FastScroll使用ExpandableListView?
的問題是,它給了我的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)
有人可以請指導我嗎? 我非常感謝您的時間和幫助。
非常感謝
您使用哪個SDK級別? – EricaCooksey 2014-11-18 19:47:57
自2014年9月起,我使用最新的Eclipse/ADT。目標Android 4.3 – Dante 2014-11-18 20:19:17