我有一个 Recyclerview,允许用户通过向上滑动来更改比例,我为此使用gestureDetector 和 onFling,这工作正常,但是用户应该能够单击 recyclerView 的项目,我通过创建一个界面来做到这一点RecyclerView 并单击“活动”中的“活动”,但现在向上滑动时出现此错误。
java.lang.NullPointerException:指定为非空的参数为空:方法 kotlin.jvm.internal.Intrinsics.checkNotNullParameter,参数 e1 位于 com.example.simmone.utils.SwipeServices$GestureListener.onFling(未知来源:2)位于 android .view.GestureDetector.onTouchEvent(GestureDetector.java:763) 在 com.example.simmone.utils.SwipeServices.onTouch(SwipeServices.kt:33)
SwipeService.kt
class SwipeServices : View.OnTouchListener {
enum class SwipeDirection {
bottomToTop
}
private var rootLayout: ViewGroup? = null
private var layoutToShowHide: ViewGroup? = null
private var gestureDetector: GestureDetector? = null
private var swipeDirections: MutableList<SwipeDirection>? = null
fun initialize(rootLayout: ViewGroup, layoutToShowHide:ViewGroup?, swipeDirections: MutableList<SwipeDirection>,maxSwipeDistance: Int = 1) {
val gestureListener = GestureListener()
gestureDetector = GestureDetector(rootLayout.context, gestureListener)
this.rootLayout = rootLayout
this.layoutToShowHide = layoutToShowHide
this.swipeDirections = swipeDirections
gestureListener.MAX_SWIPE_DISTANCE …Run Code Online (Sandbox Code Playgroud)android ontouchlistener onfling gesturedetector android-recyclerview