0

I want to be able to click and swipe on my Buttons. But once I implemented the onFling method, I am unable to click on the Buttons. Does anybody know how to fix this?

Here is my code:

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.game_activity);

    GestureDetector gestureScanner = new GestureDetector(this);

    OnTouchListener onTL = new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            gestureScanner.onTouchEvent(event);
            return true;
            }
    };

    //the Buttons are in the swipeLayout
    swipeLayout = (LinearLayout) findViewById(R.id.ll_screen_bttns);

    swipeLayout.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            gestureScanner.onTouchEvent(event);
            return false;
        }
    });

    //setting OnTouchListener for all my Buttons
    for(Button b: button_list)
        b.setOnTouchListener(onTL);
}

Once I used this code I was able to fling through my Buttons but the Click functionality stopped. Does anybody know why this is?

The Buttons are in the swipeLayout so I made its OnTouchListener return false. I guess that is wrong. How do I make the Buttons clickable and swipeable?

user2456977
  • 3,830
  • 14
  • 48
  • 87
  • You replace any and all touch functionality of buttons with just the one of `onTL`. If you remove the last two lines click event should handle correctly. – Eugen Pechanec Dec 07 '14 at 17:35
  • I removed the last two lines and now I am able to click but unable to swipe... please helpp – user2456977 Dec 07 '14 at 18:12
  • I also have a few linear layouts inside the main linear layout. And each of those linear layouts contains my buttons. Do I need to include them in the code? – user2456977 Dec 07 '14 at 19:38

0 Answers0