我创建了自己的适配器 - 实现了ListAdapter。
我在XML中检查了fastScrollEnabled:android:fastScrollEnabled="true"
。
但是,当绘制列表/网格时,我得到了一个ClassCastException:
09-29 17:23:27.333: E/AndroidRuntime(25515): FATAL EXCEPTION: main
09-29 17:23:27.333: E/AndroidRuntime(25515): java.lang.ClassCastException: XAdapter cannot be cast to android.widget.BaseAdapter
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.widget.FastScroller.getSectionsFromIndexer(FastScroller.java:541)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.widget.FastScroller.getThumbPositionForListPosition(FastScroller.java:662)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.widget.FastScroller.onScroll(FastScroller.java:487)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.widget.AbsListView.invokeOnItemScrollListener(AbsListView.java:1337)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.widget.GridView.layoutChildren(GridView.java:1301)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.widget.AbsListView.onLayout(AbsListView.java:2012)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.view.View.layout(View.java:14289)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.view.ViewGroup.layout(ViewGroup.java:4559)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.view.View.layout(View.java:14289)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.view.ViewGroup.layout(ViewGroup.java:4559)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.view.View.layout(View.java:14289)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.view.ViewGroup.layout(ViewGroup.java:4559)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.view.View.layout(View.java:14289)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.view.ViewGroup.layout(ViewGroup.java:4559)
09-29 17:23:27.333: E/AndroidRuntime(25515): at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:349)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.view.View.layout(View.java:14289)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.view.ViewGroup.layout(ViewGroup.java:4559)
09-29 17:23:27.333: E/AndroidRuntime(25515): at com.slidingmenu.lib.CustomViewAbove.onLayout(CustomViewAbove.java:470)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.view.View.layout(View.java:14289)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.view.ViewGroup.layout(ViewGroup.java:4559)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.view.View.layout(View.java:14289)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.view.ViewGroup.layout(ViewGroup.java:4559)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.view.View.layout(View.java:14289)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.view.ViewGroup.layout(ViewGroup.java:4559)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.view.Choreographer.doFrame(Choreographer.java:532)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.os.Handler.handleCallback(Handler.java:730)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.os.Handler.dispatchMessage(Handler.java:92)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.os.Looper.loop(Looper.java:137)
09-29 17:23:27.333: E/AndroidRuntime(25515): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-29 17:23:27.333: E/AndroidRuntime(25515): at java.lang.reflect.Method.invokeNative(Native Method)
09-29 17:23:27.333: E/AndroidRuntime(25515): at java.lang.reflect.Method.invoke(Method.java:525)
09-29 17:23:27.333: E/AndroidRuntime(25515): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-29 17:23:27.333: E/AndroidRuntime(25515): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-29 17:23:27.333: E/AndroidRuntime(25515): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:7)
好吧,如果你想要启用快速滚动,Android的内置代码似乎假设你正在使用BaseAdapter。
找不到关于这个主题的信息,所以想到在SO上发布这个信息。
解决方案是扩展BaseAdapter 。我不想这样做,因为我有自己的监听/刷新机制,但是如果没有太多摇动船,我找不到不同的解决方案。
进一步研究FastScroller,我不明白为什么它基于BaseAdapter,而不是ListAdapter或只是适配器。