开发者

Gesture (swipe) listener won't work for any widget but a Button

开发者 https://www.devze.com 2023-01-25 06:05 出处:网络
I\'ve got a swipe listener, based on SimpleOnGestureListener that works very well, as long as I attach it to a button like so:

I've got a swipe listener, based on SimpleOnGestureListener that works very well, as long as I attach it to a button like so:

final GestureDetector detector = new GestureDetector(MyGestureListener());
View.OnTouchListener listener 开发者_Python百科= new View.OnTouchListener() {
    public boolean onTouch(View v, MotionEvent e) {
        if(detector.onTouchEvent(e)) {
            return true;
        }
        else {
            return false;
        }
     }
};

findViewById(R.id.widget).setOnTouchListener(listener);

However, if I change "widget" to something other than a Button, like a LinearLayout or a TextView, it no longer works. Is there something I have to do to make it work with other widgets?


I feel dumb, but I got it working by calling myTextView.setClickable(true)

0

精彩评论

暂无评论...
验证码 换一张
取 消