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 3459374
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:05:55+00:00 2026-05-18T10:05:55+00:00

Well I have made a custom Android UI, and I need my UI view

  • 0

Well I have made a custom Android UI, and I need my UI view to handle this control.

a) While my mouse button is pressed (onDown / Key pressed) , the view should keep doing a thing (For example : Key is down)

b) As soon as i release my mouse key , the view should say (example: Key is up).

The Sample Flow should be something like when I press the view.

Output:
(I press mouse button on the view and hold it)

Key is down

Key is down

Key is down

Key is down

Key is down

Key is down

(I now release mouse button)

Key is up.

To more explain my problem . I am posting a code snippet where the logic should go

@Override

public boolean onTouchEvent(MotionEvent event) {
    Log.d(TAG, event.getAction());
}

When I press my mouse button , it prints “0” (meaning mouse is down), while if i leave it , it prints on the log “1”, meaning mouse is up. That should help with the logic.

Thanks for helping.


Well I have tried something like

private static int checkValue = 0;

@Override

public boolean onTouchEvent(MotionEvent event) {

    checkValue = event.getAction();

    while (checkValue == 0 ){

    Log.d(TAG, "Pressed");
    checkValue = checkMethod(event.getAction);


}

    private int checkMethod(int test){

    if (checkValue == 0){

      checkValue = 0;
      }

    else checkValue = 1;
}
  • 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-05-18T10:05:55+00:00Added an answer on May 18, 2026 at 10:05 am

    Just define an OnTouchEventListener…

    private OnTouchListener onTouchListener = new OnTouchListener() {
    
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (v.getId() == R.id.button) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    //start loop or background task
                } else if (event.getAction() == MotionEvent.ACTION_UP) {
                    //do something different
                }
            } 
            return true;
        }
    } 
    

    …and assign it to your button.

    button.setOnTouchListener(onTouchListener);
    

    When the user touches the button the ACTION_DOWN event is fired. When the user releases the button, the ACTION_UP event is fired. If you want you can start a loop in a thread which can check against a boolean variable. I didn’t check if it is correct but it should look like this:

    private OnTouchListener onTouchListener = new OnTouchListener() {
    
            private boolean flag = false;
    
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (v.getId() == R.id.button) {
                    if (event.getAction() == MotionEvent.ACTION_DOWN) {
                        flag = true;
                        Thread thread = new Thread(new Runnable() {
    
                            @Override
                            public void run() {
                                while(flag) {
                                    //do something
                                }
                            }
                        });
                        thread.start();
                    } else if (event.getAction() == MotionEvent.ACTION_UP) {
                        flag = false;
                    }
                } 
                return true;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a custom trackbar control, mostly as an exercise. I know i
I have made my own custom little blog and well, I realized it was
I have an online text editor, very well made however it does not currently
well i have a configuration like this in the components part of my config
Well i have a div tag that i show as a modal dialog this
I have made a custom UINavigationController class so that I can have a UIAlertView
In my application I have made my own Actionbar, and it works very well.
I have a custom view controller that has a view on the bottom half.
I have a custom made slideshow object to perform the usual stuff the name
I have a custom made web-site in Python/MySQL with custom user/session tables and users

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.