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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:21:15+00:00 2026-06-03T04:21:15+00:00

I am running into a problem when I try to reassign an OnClickListener. In

  • 0

I am running into a problem when I try to reassign an OnClickListener. In the code below, my program runs through the startWorkout() method and each time the button is clicked it calculates whether this is the last run through or not. If it is the last run through, it calls the lastSet() method. The lastSet() method is supposed to reasssign the button so that it does a different action but everytime I click it, it does the stuff declared in the startWorkout() method.

When I ran it through a debug mode, stepping through, the program correctly went through the lastSet() method and assigned the listener. But then it went back to the startWorkout() method and reassigned the listener! So by the time a user clicked it, the button was back to its original listener instead of the final listener.

Does anyone know why this is happening?

public  void startWorkout() {
    doSet();
    Button doneButton = (Button)findViewById(R.id.done);
    doneButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            // If this is the last result, calls last(set) instead
            saveResult();
            takeRest(61000, 30000);
        }
    });

}

public void lastSet() {
    // Changes layout (keeps the same button)
    setLayoutTest();
    Button doneButton = (Button)findViewById(R.id.done);
    doneButton.setOnClickListener(new View.OnClickListener() {


        @Override
        public void onClick(View v) {
            // Call Finish Methods

        }
    });
}
  • 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-03T04:21:16+00:00Added an answer on June 3, 2026 at 4:21 am

    Solved it…I was actually assigning the listener twice… (solved a long time ago, just cleaning up my stackoverflow questions)

    If you do this:

    doneButton.setOnClickListener(new View.OnClickListener() {
    
        @Override
        public void onClick(View v) {
    
            // If this is the last result, calls last(set) instead
            saveResult();
            takeRest(61000, 30000);
        }
    });
    

    and then this:

    doneButton.setOnClickListener(new View.OnClickListener() {
    
        @Override
        public void onClick(View v) {
    
            runMethod2();
        }
    });
    

    then ONLY the second one (runMethod2() in this case) will run. Rookie mistake, just be sure to delete (or overwrite) any legacy code.

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

Sidebar

Related Questions

I am writing my first python program and I am running into a problem
im running into this problem as i try to run a piece of django
I'm running into a problem with the following Python 3.2.2 code. The code is
So I'm running into a problem where the try: except: mechanism doesn't seem to
I am running into this problem. my program invokes Runtime.getRuntime().exec(cmd); on a windows platform.
I think I'm running into a common problem: I would like to try to
******QUESTION WAS EDITED, Please see below** I am running into a problem when I'm
I'm running into a problem with spaces in my parameters that I try to
I'm using Velocity to generate java code and I'm running into a problem with
Running into a problem. I have a table defined to hold the values of

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.