Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ViewPager禁用刷卡_Java_Android_Listview_Android Fragments - Fatal编程技术网

Java ViewPager禁用刷卡

Java ViewPager禁用刷卡,java,android,listview,android-fragments,Java,Android,Listview,Android Fragments,我有一个ViewPager,它有3个片段。左边是A,右边是B,右边是C。片段C有一个列表视图,它占据了整个屏幕的宽度。我使用以下代码在我的ListView项目上实现了一个滑动侦听器: 刷卡检测器: public class SwipeDetector implements View.OnTouchListener { public static enum Action { LR, // Left to Right RL, // Right to Left TB, //

我有一个
ViewPager
,它有3个片段。左边是A,右边是B,右边是C。片段C有一个
列表视图
,它占据了整个屏幕的宽度。我使用以下代码在我的ListView项目上实现了一个滑动侦听器:

刷卡检测器:

public class SwipeDetector implements View.OnTouchListener {

public static enum Action {
    LR, // Left to Right
    RL, // Right to Left
    TB, // Top to bottom
    BT, // Bottom to Top
    None // when no action was detected
}



private static final String logTag = "SwipeDetector";
private static final int MIN_DISTANCE = 100;
private static final int VERTICAL_MIN_DISTANCE = 80;
private static final int HORIZONTAL_MIN_DISTANCE = 80;
private float downX, downY, upX, upY;
private Action mSwipeDetected = Action.None;

public boolean swipeDetected() {
    return mSwipeDetected != Action.None;
}

public Action getAction() {
    return mSwipeDetected;
}

@Override
public boolean onTouch(View v, MotionEvent event) {
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN: {
            downX = event.getX();
            downY = event.getY();
            mSwipeDetected = Action.None;
            return false; // allow other events like Click to be processed
        }
        case MotionEvent.ACTION_MOVE: {
            upX = event.getX();
            upY = event.getY();

            float deltaX = downX - upX;
            float deltaY = downY - upY;

            // horizontal swipe detection
            if (Math.abs(deltaX) > HORIZONTAL_MIN_DISTANCE) {
                // left or right
                if (deltaX < 0) {
                   // Log.i(logTag, "Swipe Left to Right");
                    mSwipeDetected = Action.LR;
                    return true;
                }
                if (deltaX > 0) {
                   // Log.i(logTag, "Swipe Right to Left");
                    mSwipeDetected = Action.RL;
                    return true;
                }
            } else

                // vertical swipe detection
                if (Math.abs(deltaY) > VERTICAL_MIN_DISTANCE) {
                    // top or down
                    if (deltaY < 0) {
                        Log.i(logTag, "Swipe Top to Bottom");
                        mSwipeDetected = Action.TB;
                        return false;
                    }
                    if (deltaY > 0) {
                        Log.i(logTag, "Swipe Bottom to Top");
                        mSwipeDetected = Action.BT;
                        return false;
                    }
                }
            return true;
        }
    }
    return false;
}}
公共类SwipeDetector实现View.OnTouchListener{
公共静态枚举操作{
LR,//从左到右
RL,//从右到左
TB,//从上到下
BT,//从下到上
无//未检测到任何操作时
}
私有静态最终字符串logTag=“SwipeDetector”;
专用静态最终整数最小距离=100;
专用静态最终整数垂直最小距离=80;
专用静态最终整数水平最小距离=80;
私人浮动downX,downY,upX,upY;
私有操作mSwipeDetected=操作。无;
公共布尔swipedtected(){
返回mSwipeDetected!=操作。无;
}
公共行动{
检测到返回消息;
}
@凌驾
公共布尔onTouch(视图v,运动事件){
开关(event.getAction()){
case MotionEvent.ACTION\u DOWN:{
downX=event.getX();
downY=event.getY();
mSwipeDetected=操作。无;
return false;//允许处理单击等其他事件
}
case MotionEvent.ACTION\u移动:{
upX=event.getX();
upY=event.getY();
浮动deltaX=downX-upX;
浮动三角洲=downY-upY;
//水平扫描检测
if(数学绝对值(deltaX)>水平最小距离){
//左还是右
如果(deltaX<0){
//Log.i(logTag,“从左向右滑动”);
mSwipeDetected=Action.LR;
返回true;
}
如果(deltaX>0){
//Log.i(logTag,“从右向左滑动”);
mSwipeDetected=Action.RL;
返回true;
}
}否则
//垂直扫描检测
if(数学绝对值(deltaY)>垂直最小距离){
//自上而下
如果(三角洲<0){
Log.i(logTag,“从上到下滑动”);
mSwipeDetected=Action.TB;
返回false;
}
如果(三角洲>0){
Log.i(logTag,“从下到上滑动”);
mSwipeDetected=Action.BT;
返回false;
}
}
返回true;
}
}
返回false;
}}
我使用它的方式如下:

        listView.setOnTouchListener(swipeDetector);

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
                                final int position, long id) {
            Log.d("CLICKED", "CLICKED");
            if (swipeDetector.swipeDetected()) {
                Log.d("SWIPING", "SWIPING");
                Log.d("ACTION", swipeDetector.getAction().toString());
                final Button del = (Button) view.findViewById(R.id.delete_button);
                if (swipeDetector.getAction() == SwipeDetector.Action.LR) {
                    Log.d("LEFT TO RIGHT", "Left to right");
listView.setOnTouchListener(SwipedTector);
setOnItemClickListener(新的AdapterView.OnItemClickListener(){
public void onItemClick(AdapterView父级、视图、,
最终整数位置,长id){
Log.d(“点击”、“点击”);
if(swipedtector.swipedtected()){
Log.d(“刷卡”、“刷卡”);
Log.d(“ACTION”,swipedtector.getAction().toString());
final Button del=(Button)view.findViewById(R.id.delete_按钮);
if(swipedtector.getAction()==swipedtector.Action.LR){
Log.d(“从左到右”、“从左到右”);
这对活动非常有效。但是,现在的问题是,当我滑动时,它假定我在ViewPager中滑动,并将我带回中间的片段。有没有办法禁用ViewPager在该ListView上滑动或更改焦点以使其工作