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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:17:37+00:00 2026-05-26T16:17:37+00:00

I have implemented button’s onLongClickListener in Android Dialog which auto-decreases number using timers. Here

  • 0

I have implemented button’s onLongClickListener in Android Dialog which auto-decreases number using timers. Here is the code

myIncreaseTimer = new Timer();
final Runnable runnable_decrease = new Runnable() {
    public void run() {
        int txt = Integer.parseInt(length.getText().toString());
        txt -= 1;
        length.setText(String.valueOf(txt));
        if (txt == 0) {
            myIncreaseTimer.cancel();
            myIncreaseTimer.purge();
            myIncreaseTimer = new Timer();
        }
    }
};
btnMinus.setOnLongClickListener(new View.OnLongClickListener() {
    public boolean onLongClick(View v) {
        myIncreaseTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                runOnUiThread(runnable_decrease);
            }
        }, 0, 300);
        return true;
    }
});

When I am inside of activity, not dialog, I can stop the decrease via onTouchEvent when a user touches the screen

@Override 
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_UP) {
        myIncreaseTimer.cancel();
        myIncreaseTimer.purge();
        myIncreaseTimer = new Timer();
    }
    return true;
}

However, I cannot do this in the dialog. Even more, the dialog does not have onTouchEvent.

Does anyone know how can I either implement onTouchEvent in Dialog or where should I stop the increase timer in the Dialog?

  • 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-26T16:17:38+00:00Added an answer on May 26, 2026 at 4:17 pm

    You can’t handle onTouch on Dialog so

    Create a Activity, implement onTouchListener on it,
    and in manifest file

    <activity android:theme="@android:style/Theme.Dialog">
    

    So, now your activity is look like a DialogBox,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented button which clicks and opens dialog with spinner inside as described
We have implemented a popup window as a modal dialog using the IE method:
I have implemented my custom button inheriting from CButton and drawing it by using
Hi I have implemented this code: Button goToRegister = (Button) findViewById(R.id.reg); goToRegister.setOnClickListener(new View.OnClickListener() {
I have implemented an error style for textboxes using the following code. This sets
In Button click I have implemented the code, when I click the button first
I have implemented the Facebook like button on my site by using the asynchronous
I have implemented one up button and one down button in my layout.xml which
I have implemented a refresh button of style UIBarSystemItem which will be disabled for
I have implemented tracing based on System.Diagnostics. I am also using a System.Diagnostics.TextWriterTraceListener, and

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.