Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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
Android Listview阻止手势_Android - Fatal编程技术网

Android Listview阻止手势

Android Listview阻止手势,android,Android,好的,我已经实现了一些手势,包括向左和向右投掷,在每一侧开始新的活动。一切都应该完美运作。当我设置列表视图项时,列表视图开始阻止我的手势。我搜索了dispatchTouchEvent,它为您提供了touch事件的优先级,因为我不知道如何在我的案例中实现它。请帮忙。我想应该是这样的: public class Main extends Activity { GestureDetectorCompat gdc; ListView list; @Override protected void onCr

好的,我已经实现了一些手势,包括向左和向右投掷,在每一侧开始新的活动。一切都应该完美运作。当我设置列表视图项时,列表视图开始阻止我的手势。我搜索了dispatchTouchEvent,它为您提供了touch事件的优先级,因为我不知道如何在我的案例中实现它。请帮忙。

我想应该是这样的:

public class Main extends Activity {
GestureDetectorCompat gdc;
ListView list;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);  
    list = (ListView) findViewById(R.id.listview);
    gdc = new GestureDetectorCompat(this, new GesturesClass());
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    gdc.onTouchEvent(event);
    return super.onTouchEvent(event);
}


class GesturesClass extends SimpleOnGestureListener {

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
        //Bring left activity
        if((e2.getX() - e1.getX()) > 100){
            Intent intent = new Intent(Main.this, Finished.class);
            startActivity(intent);
            Toast.makeText(Main.this, "Bring left actitivty.", Toast.LENGTH_LONG).show();
        }else if((Math.abs(e1.getX() - e2.getX())) > 100){
            Toast.makeText(Main.this, "Bring right actitivty.", Toast.LENGTH_LONG).show();              
            Intent intent = new Intent(Main.this, Unfinished.class);
            startActivity(intent);
        }
        return super.onFling(e1, e2, velocityX, velocityY);
    }
}
编辑:

列表视图
添加一个自定义的
onTouchListener
,并让它
返回gdc.onTouchEvent(事件)


我认为应该是这样的:

public class Main extends Activity {
GestureDetectorCompat gdc;
ListView list;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);  
    list = (ListView) findViewById(R.id.listview);
    gdc = new GestureDetectorCompat(this, new GesturesClass());
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    gdc.onTouchEvent(event);
    return super.onTouchEvent(event);
}


class GesturesClass extends SimpleOnGestureListener {

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
        //Bring left activity
        if((e2.getX() - e1.getX()) > 100){
            Intent intent = new Intent(Main.this, Finished.class);
            startActivity(intent);
            Toast.makeText(Main.this, "Bring left actitivty.", Toast.LENGTH_LONG).show();
        }else if((Math.abs(e1.getX() - e2.getX())) > 100){
            Toast.makeText(Main.this, "Bring right actitivty.", Toast.LENGTH_LONG).show();              
            Intent intent = new Intent(Main.this, Unfinished.class);
            startActivity(intent);
        }
        return super.onFling(e1, e2, velocityX, velocityY);
    }
}
编辑:

列表视图
添加一个自定义的
onTouchListener
,并让它
返回gdc.onTouchEvent(事件)


我认为应该是这样的:

public class Main extends Activity {
GestureDetectorCompat gdc;
ListView list;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);  
    list = (ListView) findViewById(R.id.listview);
    gdc = new GestureDetectorCompat(this, new GesturesClass());
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    gdc.onTouchEvent(event);
    return super.onTouchEvent(event);
}


class GesturesClass extends SimpleOnGestureListener {

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
        //Bring left activity
        if((e2.getX() - e1.getX()) > 100){
            Intent intent = new Intent(Main.this, Finished.class);
            startActivity(intent);
            Toast.makeText(Main.this, "Bring left actitivty.", Toast.LENGTH_LONG).show();
        }else if((Math.abs(e1.getX() - e2.getX())) > 100){
            Toast.makeText(Main.this, "Bring right actitivty.", Toast.LENGTH_LONG).show();              
            Intent intent = new Intent(Main.this, Unfinished.class);
            startActivity(intent);
        }
        return super.onFling(e1, e2, velocityX, velocityY);
    }
}
编辑:

列表视图
添加一个自定义的
onTouchListener
,并让它
返回gdc.onTouchEvent(事件)


我认为应该是这样的:

public class Main extends Activity {
GestureDetectorCompat gdc;
ListView list;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);  
    list = (ListView) findViewById(R.id.listview);
    gdc = new GestureDetectorCompat(this, new GesturesClass());
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    gdc.onTouchEvent(event);
    return super.onTouchEvent(event);
}


class GesturesClass extends SimpleOnGestureListener {

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
        //Bring left activity
        if((e2.getX() - e1.getX()) > 100){
            Intent intent = new Intent(Main.this, Finished.class);
            startActivity(intent);
            Toast.makeText(Main.this, "Bring left actitivty.", Toast.LENGTH_LONG).show();
        }else if((Math.abs(e1.getX() - e2.getX())) > 100){
            Toast.makeText(Main.this, "Bring right actitivty.", Toast.LENGTH_LONG).show();              
            Intent intent = new Intent(Main.this, Unfinished.class);
            startActivity(intent);
        }
        return super.onFling(e1, e2, velocityX, velocityY);
    }
}
编辑:

列表视图
添加一个自定义的
onTouchListener
,并让它
返回gdc.onTouchEvent(事件)


它按照我的方式运作。尽管listview仍然阻止手势,但是您应该为listview添加一个自定义onTouchListener,如果
返回gdc.onTouchEvent(事件)它按照我实现的方式工作。尽管listview仍然阻止手势,但是您应该为listview添加一个自定义onTouchListener,如果
返回gdc.onTouchEvent(事件)它按照我实现的方式工作。尽管listview仍然阻止手势,但是您应该为listview添加一个自定义onTouchListener,如果
返回gdc.onTouchEvent(事件)它按照我实现的方式工作。尽管listview仍然阻止手势,但是您应该为listview添加一个自定义onTouchListener,如果
返回gdc.onTouchEvent(事件)