这是MyCustomRecyclerView.java
public class MyCustomRecyclerView extends RecyclerView {
private GestureDetectorCompat gestureDetector;
public MyCustomRecyclerView(@NonNull Context context) {
super(context);
init(context, null);
}
public MyCustomRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public MyCustomRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
private void init(Context context, AttributeSet attrs) {
gestureDetector = new GestureDetectorCompat(context, gestureListener);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent e) {
gestureDetector.onTouchEvent(e);
return super.onInterceptTouchEvent(e);
}
private final GestureDetector.OnGestureListener gestureListener = new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
if (getParent() != null)
getParent().requestDisallowInterceptTouchEvent(true);
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
Log.i("TAG", "onFling: ");
return super.onFling(e1, e2, velocityX, velocityY);
}
@Override
public boolean onDown(MotionEvent e) {
Toast.makeText(getContext(), " Swipe Down ", Toast.LENGTH_SHORT).show();
Intent hmmIntent = new Intent(getContext(),HmmActivity);
startActivity(hmmIntent);
return super.onDown(e);
}
};
Intent homeIntent =新的Intent(getContext(),HomeActivity); startActivity(homeIntent);' 行给我错误。除了这一类外,我还有MyRecyclerViewAdapter,MainActivity和HomeActivity类。
请帮助我解决这个问题。
答案 0 :(得分:0)
这是一个视图类,是可重用的组件,因此请勿在视图中编写项目特定的方法或回调。如下所示在您的主要活动中编写您的recyclerview onClick方法;
将其放入您的mainActivity onCreate()方法:
./cuda_9.0.176_384.81_linux.run --silent --toolkit --toolkitpath=/tmp
./cuda_9.0.176.1_linux.run --silent --accept-eula --installdir=/tmp
还应该调用finish();在startActivity()
之后