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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:40:51+00:00 2026-06-13T04:40:51+00:00

My app has several buttons which their text on them is a counter. Each

  • 0

My app has several buttons which their text on them is a counter. Each button with a different counter. I want to start whichever i want 2 independently. My problem is that when i press one button all the other button counter start. So i have many buttons to start a counter when just one is pressed. I know there are many lol apps for this but i want to practice on coding android:P I know the problem is on the onTick method. But i dont know how to call many onTick methods one for each button, or have if/switch statements inside the onTick. Anyone knows how can i do this?

Thank u for your time

public class TimersActivity extends Activity {

Button wraith, wolf, golem, blue_golem, red_golem, enemy_wraith, enemy_wolf, enemy_golem, enemy_blue_golem, enemy_red_golem, dragon, baron;

final MyCounter wraithTimer = new MyCounter(50000,100, wraith);
final MyCounter enemy_wraithTimer = new MyCounter(50000,100, wolf);

final MyCounter wolfTimer = new MyCounter(60000,100, null);
final MyCounter enemy_wolfTimer = new MyCounter(60000,100, null);
final MyCounter golemTimer = new MyCounter(60000,100, null);
final MyCounter enemy_golemTimer = new MyCounter(60000,100, null);
final MyCounter blue_golemTimer = new MyCounter(300000,100, null);
final MyCounter enemy_blue_golemTimer = new MyCounter(300000,100, null);
final MyCounter red_golemTimer = new MyCounter(300000,100, null);
final MyCounter enemy_red_golemTimer = new MyCounter(300000,100, null);
final MyCounter dragonTimer = new MyCounter(360000,100, null);
final MyCounter baronTimer = new MyCounter(420000,100, null);

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_timers);

        wraith = (Button)findViewById(R.id.wraiths);
        wolf = (Button)findViewById(R.id.wolfs);
        golem = (Button)findViewById(R.id.golems);
        blue_golem = (Button)findViewById(R.id.blue_golem);
        red_golem = (Button)findViewById(R.id.redbuff_creep);
        enemy_wraith = (Button)findViewById(R.id.enemy_wraiths);
        enemy_wolf = (Button)findViewById(R.id.enemy_wolfs);
        enemy_golem = (Button)findViewById(R.id.enemy_golems);
        enemy_blue_golem = (Button)findViewById(R.id.enemy_blue_golem);
        enemy_red_golem = (Button)findViewById(R.id.enemy_redbuff_creep);
        dragon = (Button)findViewById(R.id.dragon);
        baron = (Button)findViewById(R.id.baron);

        wraith.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                wraithTimer.start();
            }
        });

    }

    public enum buttons{wraith,wolf};
    public class MyCounter extends CountDownTimer{



        public MyCounter(long millisInFuture, long countDownInterval, Button nam) {
            super(millisInFuture, countDownInterval);
        }


        public void onFinish() {
            wraith.setText("DONE");

        }
        public void onTick(long millisUntilFinished, buttons names) {

            switch(names){

            case wraith: 
                wraith.setText((millisUntilFinished/1000)+"");
                break;
            case wolf: 
                 wolf.setText((millisUntilFinished/1000)+"");
                 break;         
            }

        }


        public void onTick(long millisUntilFinished) {
            // TODO Auto-generated method stub

        }

    }

}
  • 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-13T04:40:52+00:00Added an answer on June 13, 2026 at 4:40 am

    One option would be to use Enums in the MyCounter class.

    Simply assign it in the constructor, then in the onTick() method, use a switch with the enum as parameter.


    edit:

    using the enum in the constructor would mean using this code in the initializers:

    final MyCounter <name>Timer = new MyCounter(x0000, 100, buttons.wraith);
    

    In your MyCounter class add a private field in which you store the enum like so:

    private buttons button;
    

    and in your constructor, assign the enum:

    public MyCounter(long millisInFutre, long countdownInterval, buttons name) {
        super(millisInFutre, countdownInterval);
        this.button = name;
    }
    

    then the onTick method should be called as usual:

    public void onTick(long millisUntilFinished) {
        switch(button) {
        case buttons.wraith:
            wraith.setText(...);
            break;
        }
    }
    

    Hope you’ll finish this 🙂

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

Sidebar

Related Questions

My app has several buttons which trigger different events. The user should NOT be
I'm building an app that has several different sections to it, all of which
I have a winforms app and the main (and only) form has several buttons.
I am working on an app that has several different views, two of the
I am developing an app which has several viewControllers. The first one is MainMenu
I have an app which shows boxes within boxes. Each box model has a
My Android app Transdroid offers several home screen widgets. Every AppWidget has 2 'buttons'
My app has several activities which can be thought of as separate levels in
Ive got a jquery app that has several grids (jqgrid) in defferent tabs. Below
I'm working on a PHP app that has several objects that can be commented

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.