[英]setOnTouchListener and setOnItemLongClickListener mutually exclusive?
In the code below, onItemLongClick works only when I comment out the onTouchListener. 在下面的代码中,仅当我注释掉onTouchListener时,onItemLongClick才起作用。 I need to be able to register swipes as well as long clicks.
我需要能够注册滑动以及长按。 What am I doing wrong?
我究竟做错了什么?
public class MainPageActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
...
getListView().setLongClickable(true);
getListView().setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(), "long click", Toast.LENGTH_SHORT).show();
return true;
}
});
getListView().setOnTouchListener(new OnSwipeTouchListener() {
public void onSwipeBottom() {
Toast.makeText(MainPageActivity.this, "bottom", Toast.LENGTH_SHORT).show();
}
});
}
}
如果您在OnTouchListener
, SimpleGestureListener
或类似方法中覆盖onTouch,onDown或类似的其他方法,则需要确保您返回的是false,以便事件能够正确传播。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.