2

我创建了自己的适配器 - 实现 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)
4

1 回答 1

7

好吧,如果您想启用快速滚动,Android 的内置代码似乎假定您正在使用 BaseAdapter。

找不到有关该主题的信息,因此想在 SO 上发布此信息。

解决方案是扩展 BaseAdapter。我不想这样做,因为我有自己的侦听/刷新机制,但是如果不过度摇晃船,我就找不到不同的解决方案。

进一步研究 FastScroller,我不明白为什么它如此基于 BaseAdapter 而不是 ListAdapter 或只是 Adapter。

于 2014-09-30T10:47:24.007 回答