Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7749781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:07:28+00:00 2026-06-01T11:07:28+00:00

I have created an activity implementing on touch listener and onclick listener . Both

  • 0

I have created an activity implementing on touch listener and onclick listener .
Both are not working together. If ontouch works on click does not work and if onclick works ontouch does not works.
here is my code

 public class QuickStart extends Activity implements OnTouchListener 
    {
    private static final int SWIPE_MIN_DISTANCE = 120;
    private static final int SWIPE_MAX_OFF_PATH = 250;
    private static final int SWIPE_THRESHOLD_VELOCITY = 200;
    private GestureDetector gestureDetector;
    private ViewFlipper viewFlipper;
    int page = 0;
    private Button btn_menu;
    private LinearLayout layout_menu;
    Developer developer = new Developer();
    private ArrayList<SideMenuItem> arrayList = new ArrayList<SideMenuItem>();
    private SideMenuEntryAdapter adapter;
    private ListView list_side;
    private Context context;
    private int flag = 0;
        @Override
        protected void onCreate(Bundle savedInstanceState) {        
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.quickstart);
        context = this;
        gestureDetector = new GestureDetector(new MyGestureDetector());
        setupUI();
        arrayList = developer.setupList();
        adapter = new SideMenuEntryAdapter(this, arrayList);
        list_side.setAdapter(adapter);
        list_side.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1,
                    int position, long arg3) {
                System.out.println(position);
                Developer.Menu(context, position,Developer.quick_start);
                if (flag == 0) {
                    flag = 1;
                    layout_menu.setVisibility(LinearLayout.VISIBLE);
                } else {
                    flag = 0;
                    layout_menu.setVisibility(LinearLayout.GONE);
                }
            }
        });
    }
    private void setupUI() {
        viewFlipper = (ViewFlipper) findViewById(R.id.viewFlipper);
        viewFlipper.setOnTouchListener(this);
        btn_menu = (Button) findViewById(R.id.btn_menu);
        layout_menu = (LinearLayout) findViewById(R.id.layout_menu);
        list_side = (ListView) findViewById(R.id.listview_side);
        btn_menu.setClickable(true);
        layout_menu.setClickable(true);
        list_side.setClickable(true);
        btn_menu.setFocusable(true);
        btn_menu.setFocusableInTouchMode(true);
        layout_menu.setFocusable(true);
        layout_menu.setFocusableInTouchMode(true);
        list_side.setFocusable(true);
        list_side.setFocusableInTouchMode(true);
        btn_menu.setEnabled(true);
        layout_menu.setEnabled(true);
        list_side.setEnabled(true);
        btn_menu.setOnClickListener(new Button.OnClickListener() {
        @Override
            public void onClick(View v) {
                if (v == btn_menu) {
                    System.out.println("Menu");
                    if (flag == 0) {
                    flag = 1;
                    layout_menu.setVisibility(LinearLayout.VISIBLE);
                    } else {
                        flag = 0;
                    layout_menu.setVisibility(LinearLayout.GONE);
                    }
                }
            }
        });
    } 
    class MyGestureDetector extends SimpleOnGestureListener {
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                float velocityY) {
            try {

                if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
                    return false;
                if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
                        && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                    if (page < 7) {
                        page++;
                        viewFlipper.showNext();
                    }
                } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
                        && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {

                    if (page > 0) {
                        page--;
                    viewFlipper.showPrevious();
                    }
                }
            } catch (Exception e) {
                // nothing
            }
            return false;
        }

    }
    @Override
    public boolean onTouch(View v, MotionEvent event) {
             if (gestureDetector.onTouchEvent(event)) {
                 return false;
                } else {
                 return true;
                }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:07:30+00:00Added an answer on June 1, 2026 at 11:07 am

    Make your activity implement the onGestureListener.

    then in you activity add

    private GestureDetector gestureScanner; 
    gestureScanner = new GestureDetector(this); 
    private static final int SWIPE_MIN_DISTANCE = 100;  
    private static final int SWIPE_THRESHOLD_VELOCITY = 100; 
    

    Then overrid the onTouchEvent(MotionEvent event) like below:

    @Override    
     public boolean onTouchEvent(MotionEvent event) {   
          return gestureScanner.onTouchEvent(event);    
     } 
    

    Also Finally you need to overide onFling method something like:

    @Override     
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { 
            /* on scroll to the next page */         
    if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY            ) {
                 //Ur code goes here         }        
     /* on scroll to the previous page  */ 
     else if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE  && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY                 ) {        
         //ur code goes here.        
    
     }         return false;     } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an activity which sends a number of notifications to status bar.
I have created an activity called viewActivity. It displays the shared files and folders
I am trying to display ListView . I have created one activity , in
i have created a workflow activity that do give the item creater of a
I have created a custom workflow activity that copies attachments from a case to
I have an application and every new created activity will start an async task
I have an android activity and a service implemented using aidl. Works like a
I have created an Activity (CodeActivity) that retrieves the temperature where I live. I
I have created an Activity with a AutuCompleteTextView[ACTV] and button. I enter some text
I have created an abstract class which extends the Activity Class. I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.