Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Android studio | how to make a button text unchangable after changing it once

  1. #1
    Junior Member
    Join Date
    Mar 2019
    Location
    India
    Posts
    18
    My Mood
    Confused
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Android studio | how to make a button text unchangable after changing it once

    suppose
    button1.setonclicklistener(){
    button1.settext( "Awaiting")
    }
    is what I assigned first
    then I assigned it to
    button1.setonclicklisterner(){
    button1.settext("player1 won")}
    Now in my code I want this to be set permanently
    as I am using it to make a tic tac toe game changes the button1.settext after every press
    any idea how to make the text permanent?

  2. #2
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    277
    My Mood
    Amused
    Thanks
    8
    Thanked 19 Times in 19 Posts

    Default Re: Android studio | how to make a button text unchangable after changing it once

    Mean you want it be "player1 won" permanently?
    Whatever you are, be a good one

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Android studio | how to make a button text unchangable after changing it once

    One way would be to have a variable that says if the target variable can be changed:
      if(canChange) {  // test if allowed to make the change
          //  make the change to the target variable
          canChange = false;    // set so that future execution will not make a change
     }
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Member
    Join Date
    Sep 2018
    Location
    Virginia
    Posts
    284
    My Mood
    Cool
    Thanks
    0
    Thanked 38 Times in 36 Posts

    Default Re: Android studio | how to make a button text unchangable after changing it once

    The easiest way would be to disable the button. It will then change the textual appearance to indicate it has been disabled.
    JButton b = myButton("X");
    b.setEnabled(false);
    Regards,
    Jim
    Last edited by jim829; May 21st, 2019 at 04:54 PM.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Android studio | how to make a button text unchangable after changing it once

    Does disabling an Android button prevent its text being changed? It doesn't in Swing.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Member
    Join Date
    Sep 2018
    Location
    Virginia
    Posts
    284
    My Mood
    Cool
    Thanks
    0
    Thanked 38 Times in 36 Posts

    Default Re: Android studio | how to make a button text unchangable after changing it once

    I may have misunderstood the question. I thought the OP didn't want to be able to press the button again, once it has been changed.

    Regards,
    Jim

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Android studio | how to make a button text unchangable after changing it once

    If the button only changes itself, then disabling it would keep it from doing that. So your solution would work.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Facing a problem in android studio ( java )
    By fallen01 in forum Android Development
    Replies: 22
    Last Post: December 31st, 2018, 03:07 AM
  2. android studio problem
    By pingusteam in forum Android Development
    Replies: 3
    Last Post: August 30th, 2018, 03:27 PM
  3. Integrate Android studio with lwuit
    By youssef77 in forum Android Development
    Replies: 0
    Last Post: August 2nd, 2014, 08:17 AM
  4. Replies: 0
    Last Post: January 4th, 2014, 02:25 PM
  5. need help in changing button and highscore
    By nabil.elpistolero in forum Java Theory & Questions
    Replies: 6
    Last Post: April 4th, 2012, 12:06 PM

Tags for this Thread