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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:47:46+00:00 2026-05-18T23:47:46+00:00

I have a button in my activity, when you click the button an if

  • 0

I have a button in my activity, when you click the button an if statement is ran against its text label;

if(BTN_1.getText()=="firsttext"){
    //do some stuff, then...
    BTN_1.setText("secondtext");
}else if(BTN_1.getText()=="secondtext"){
    //do other stuff, then...
    BTN_1.setText("firsttext");
}

Firstly, if I hit the home button and go back to the desktop and then click back onto my app the view has reset its self; if I press the button and leave it in a state where the text of the button is “secondtext”, when I return to my app it says “firsttext”, how can I stop the view of my app refreshing its self like this?

Secondly, under my XML layout I have defined the buttons text; android:text=”firsttext”
But this won’t actually match my if statement above, under onCreate of this app I have: BTN_CONNECT.setText(“Connect”);
But visually the text of the button is exactly the same, why won’t it match?

Thanks for reading 🙂

  • 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-18T23:47:47+00:00Added an answer on May 18, 2026 at 11:47 pm

    Where do I start?

    • String compares need to be done with equals(), not ==.
    • String compares to check your state are bad to begin with. Use an integer/enum to see manage your state.
    • Depending on how long you want your state to persist, you can either do it in Activity.saveInstanceState() (so it will persist if you change orientation), or in the SharedPreferences if you want it to persist forever.
    • Don’t use hard-coded strings for android:text, use resources, so you can translate them.
    • I don’t understand your last point.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application i have three activity. In my third activity if i click
I have a button that when clicked, saves a canvas to an image file
I have a button defined in my XML file. The button works exactly like
I have an Android application which has four tabs (I use a main TabActivity
I want to have a common bottom bar in Android. If any of the
How would I call a method from a different activity? In my main activity,
I have a view which is pushed onto the UINavigationController stack from another UITableView.
I have written a mapping application which can either use Google Maps or Open
I've been working at this all day, and I'm really close but just can't

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.