blast_z 2016-09-07 13:12 采纳率: 42.9%
浏览 2811
已采纳

GestureDetector没用 滑动屏幕没反应

public class AttributeActivity extends Activity implements GestureDetector.OnGestureListener{
private ListView listView;
private static final int FLIP_DISTANCE=80;
private GestureDetector detector;
List persons;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.attribute_main);
detector=new GestureDetector(AttributeActivity.this,AttributeActivity.this);
Intent intent=getIntent();
Bundle data=intent.getExtras();
persons=(List)data.getSerializable("MainActivity_persons");
listView=(ListView)findViewById(R.id.listView_attribute_main);
PersonAdapter personAdapter=new PersonAdapter(AttributeActivity.this,R.layout.list_item,persons);
listView.setAdapter(personAdapter);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return detector.onTouchEvent(event);
}

@Override
public void onShowPress(MotionEvent e) {

}

@Override
public void onLongPress(MotionEvent e) {

}

@Override
public boolean onSingleTapUp(MotionEvent e) {
    return false;
}

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
    return false;
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    Toast.makeText(AttributeActivity.this, "onFling()", Toast.LENGTH_SHORT).show();
    if(e2.getX()-e1.getX()>=FLIP_DISTANCE){
        Intent intent=new Intent(AttributeActivity.this,MainActivity.class);
        startActivity(intent);
        return true;
    }
    return false;
}

@Override
public boolean onDown(MotionEvent e) {
    return false;
}

}

滑了滑屏幕没反应 哪里有问题

  • 写回答

2条回答

  • DreamerJ 2016-09-07 13:50
    关注
    @Override
        public boolean dispatchTouchEvent(MotionEvent ev) {
            detector.onTouchEvent(event);
            super.dispatchTouchEvent(ev);
            return false;
        } 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog