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

  • Home
  • SEARCH
  • 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 6726257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:54:21+00:00 2026-05-26T09:54:21+00:00

I am only seeing articles on how to do something after a certain amount

  • 0

I am only seeing articles on how to do something after a certain amount of time, but I want to know how to do something FOR a certain amount of time in Android.

    public void buttonClick(View v) {

        currentUser.changeScore(10);

        TextView tv = (TextView) findViewById(R.id.score);
        tv.setText("Score: " + currentUser.getScore());

    }

I want to the user to be able to press the button and gain points for 10 seconds after an Event has occured. After those 10 seconds, I want the user to lose 10 points if the button is pressed.

  • 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-26T09:54:22+00:00Added an answer on May 26, 2026 at 9:54 am

    It’s simple. Every time your event happens, set a variable, like this:

    long positivePointEndTime = 0;
    
    // In your event handler...
    positivePointEndTime = System.currentTimeMillis() + 10000;
    
    // Then in the button click handler
    int scoreChange = System.currentTimeMillis() < positivePointEndTime ? 10 : -10;
    currentUser.changeScore(scoreChange);
    

    It’s not like you’re really wanting anything to change on a regular basis during that interval – the event is just setting a new point in time as the boundary of when it’s “good” to click the button. No need for a timer or anything like that.

    (For testability you may want to have a dependency-injected Clock type or something similar to provide the “current time” functionality, but the basic principle is the same.)

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

Sidebar

Related Questions

Details: Only disable after user clicks the submit button, but before the posting back
Using only MySQL , I'm seeing if it's possible run an insert statement ONLY
I only want a list of files that have been added (not ones that
After reading a few enlightening articles about memory in the .NET technology, Out of
After using the IE8 built in Developers Tools for the first time, I noticed
When loading two CSS files via an include I am only seeing one of
Is there a way to create non-rectangular clickboxes for links? I only recall seeing
Does any one have a class diagram for magento? I'm only seeing an ERD
Only one instance of a Script Manager can be added to the page. Such
The only thing I've found has been; .hang { text-indent: -3em; margin-left: 3em; }

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.