plz帮助获取错误View无法转换为MotionEvent,MotionEvent无法转换为View ..
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.OnItemTouchListener;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
public class RecyclerTouchListener implements OnItemTouchListener {
private ClickListener clickListener;
private GestureDetector gestureDetector;
public interface ClickListener {
void onClick(View view, int i);
void onLongClick(View view, int i);
}
public void onRequestDisallowInterceptTouchEvent(boolean z) {
}
public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {
}
public RecyclerTouchListener(Context context, final RecyclerView recyclerView, final ClickListener clickListener) {
this.clickListener = clickListener;
this.gestureDetector = new GestureDetector(context, new SimpleOnGestureListener() {
public boolean onSingleTapUp(MotionEvent motionEvent) {
return true;
}
public void onLongPress(MotionEvent motionEvent) {
motionEvent = recyclerView.findChildViewUnder(motionEvent.getX(), motionEvent.getY());
if (motionEvent != null && clickListener != null) {
clickListener.onLongClick(motionEvent, recyclerView.getChildPosition(motionEvent));
}
}
});
}
public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {
View findChildViewUnder = recyclerView.findChildViewUnder(motionEvent.getX(), motionEvent.getY());
if (!(findChildViewUnder == null || this.clickListener == null || this.gestureDetector.onTouchEvent(motionEvent) == null)) {
this.clickListener.onClick(findChildViewUnder, recyclerView.getChildPosition(findChildViewUnder));
}
return null;
}
}
单个文件中的错误列表
1种无与伦比的类型:布尔值和<null>
2个不兼容的类型:无法转换为布尔值
3种不兼容的类型:视图无法转换为MotionEvent
4种不兼容的类型:MotionEvent无法转换为View
不知道如何解决这个问题。
预先感谢您的帮助
我希望很清楚,如果有错误,对不起
答案 0 :(得分:0)
在#1 Wrong. Inner join can produce anywhere between 0 and 1000 rows.
#2 Wrong. Left join can produce anywhere between 10 and 1000 rows.
#3 Wrong. Right join can produce anywhere between 100 and 1000 rows.
#4 Wrong. Full outer join can produce anywhere between 100 and 1000 rows.
#5 Wrong. Full outer join can produce anywhere between 100 and 1000 rows.
#6 Wrong. Joins can produce anywhere between 0 and 1000 rows.
#7 Correct. Joins can produce anywhere between 0 and 1000 rows.
findChildViewUnder
方法返回一个View。 MotionEvent
is a type of InputEvent
not a View
motionEvent = recyclerView.findChildViewUnder
是无效的比较,因为布尔基元永远不能为null,如果触摸被拦截,则只能为true。
类似地,this.gestureDetector.onTouchEvent(motionEvent) == null
不能onInterceptTouchEvent
您应该使用return null
而不是使用GestureDetector并从侦听器中手动调用setOnClickListener