Gesture (swipe) listener won't work for any widget but a Button
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)
精彩评论