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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:08:16+00:00 2026-06-14T05:08:16+00:00

In my program, when the user presses a button, I want to set the

  • 0

In my program, when the user presses a button, I want to set the text to something else based on what is already there, but it is not working.
When I click on the buttons, nothing happens, the text stays the same
This is the xml layout where the buttons are made. they call the function nextVal

<Button
                android:id="@+idk/kbutton1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:onClick="nextVal"
                android:text="@string/zero" />

            <Button
                android:id="@+idk/kbutton3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:onClick="nextVal"
                android:text="@string/x" />

            <Button
                android:id="@+idk/kbutton4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:onClick="nextVal"
                android:text="@string/one" />

The function that is called

public void nextVal(View view)
    {

        Button b = (Button) findViewById(view.getId());
        System.out.println(b.getText().toString());

        switch(view.getId())
        {
        case R.idk.kbutton4:
            if(b.getText().toString() == "0")
                b.setText("1");
            else if(b.getText().toString() == "1")
                b.setText("x");
            else if(b.getText().toString() == "x")
                b.setText("0");
            break;
        case R.idk.kbutton3:
            if(b.getText().toString() == "0")
                b.setText("1");
            if(b.getText().toString() == "1")
                b.setText("x");
            if(b.getText().toString() == "x")
                b.setText("0");
            break;
        case R.idk.kbutton2:
            if(b.getText().toString() == "0")
                b.setText("1");
            if(b.getText().toString() == "1")
                b.setText("x");
            if(b.getText().toString() == "x")
                b.setText("0");
            break;
        }

    }
  • 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-14T05:08:17+00:00Added an answer on June 14, 2026 at 5:08 am

    You are using the == operator to compare two strings. The == operator checks whether the reference is the same, not whether the contents are equivalent.

    Instead, you should use b.getText.ToString().equals(“x”);

    That being said, I have some additional suggestions. You’re using findViewById() to find a view that you’re already being passed. You can replace the findViewById(view.getId()) and just cast the View to Button instead.

    Also, you can get rid of the switch statement, because it’s really doing you no good except to clutter up the code. You are doing the exact same thing no matter the case, so why bother? Just replace it with the contents of one of the possibilities.

    So your nextVal() might look like:

        public void nextVal(View view)
        {
            Button b = (Button) view;
    
            if(b.getText().toString().equals("0")){
                    b.setText("1");
            }else if(b.getText().toString().equals("1")){
                    b.setText("x");
            }else if(b.getText().toString().equals("x")){
                    b.setText("0");
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a program where user input is an array of mixed Strings
I wonder if it's possible to quit my program entirely after the user presses
I've been working on an error in my program but I cannot seem to
I know that you can set actions to trigger if the user presses a
Im using visual basic 2010. Preparing a program. In my program when user presses
I am probably missing something here, but I'll try and explain what I want
I'm trying to add a notification alarm when a user presses a button private
When the user presses the close button in my form, I am executing a
My program takes user name and password authentication from user before initialising the program,
The following program expects user input in the mixed fraction format 'whole_numbernumerator/denominator' and assigns

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.