How do I find out which string resource is currently assigned to the android:text property of a button view?

hourback

In my activity, I'm trying to make decisions based on the text displayed on a button. I got it to work by doing:

if( startButton.getText() == "Stop" ) {
  startButton.setText("Start");
} else {
  startButton.setText("Stop");
}

But I'd like to do it in a way that is language independent, so by using the name of the string as it exists in strings.xml, i.e. "start_text" and "stop_text".

antoniom

You can use getTag() and setTag() E.g.

if (startButton.getTag(R.id.state).equals("play")) {
   startButton.setText("Start");
   startButton.setTag(R.id.state, "stop");
} else {
   startButton.setText("Stop");
   startButton.setTag(R.id.state, "play");
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how do i find out which network profile is currently connected to wifi using netsh command on windows

From Dev

Find out which Music is currently playing [Android]

From Dev

Find out which Music is currently playing [Android]

From Java

Tmux: How do I find out the currently running version of tmux?

From Dev

How do I concat string with the content which is a binding property in button which is inside DataTemplate in UWP?

From Dev

Multiple PSU rails: How do I find out which is which?

From Dev

How can I find out, which jar-files java is currently running (and their PIDs)?

From Dev

How can I find out, which jar-files java is currently running (and their PIDs)?

From Dev

How do I find out which boot loader I have?

From Dev

How do I find out which boot loader I have?

From Dev

How to find out which file is currently written by a process

From Dev

How to find out which file is currently opened in vim?

From Dev

Objective C IOS prepareForSegue how do I get an int variable I assigned to a button to next View controller

From Java

How do I find out which DOM element has the focus?

From Dev

How do I find out which of 2 methods is faster?

From Dev

How do I find out which application plays sound?

From Dev

How do I find out which application is disabling sleep?

From Dev

How do I find out which processes are preventing unmounting of a device?

From Dev

How do I find out which RPM was used to install PHP?

From Dev

How do I find out which application plays sound?

From Dev

How do I find out which package owns a file?

From Dev

How do I find out which GCC toolchain is installed?

From Dev

How do I find out programmatically which mode of Location is turned on?

From Dev

How do I find out which touchpad driver is being used?

From Dev

How do I find out which repository a package comes from?

From Dev

How do I find out which process is preventing a umount?

From Dev

How do I show text and a button? (android)

From Dev

How do I find out how my currently Linux kernel was configured

From Dev

How do I find the area in which the camera field of view encompasses?

Related Related

  1. 1

    how do i find out which network profile is currently connected to wifi using netsh command on windows

  2. 2

    Find out which Music is currently playing [Android]

  3. 3

    Find out which Music is currently playing [Android]

  4. 4

    Tmux: How do I find out the currently running version of tmux?

  5. 5

    How do I concat string with the content which is a binding property in button which is inside DataTemplate in UWP?

  6. 6

    Multiple PSU rails: How do I find out which is which?

  7. 7

    How can I find out, which jar-files java is currently running (and their PIDs)?

  8. 8

    How can I find out, which jar-files java is currently running (and their PIDs)?

  9. 9

    How do I find out which boot loader I have?

  10. 10

    How do I find out which boot loader I have?

  11. 11

    How to find out which file is currently written by a process

  12. 12

    How to find out which file is currently opened in vim?

  13. 13

    Objective C IOS prepareForSegue how do I get an int variable I assigned to a button to next View controller

  14. 14

    How do I find out which DOM element has the focus?

  15. 15

    How do I find out which of 2 methods is faster?

  16. 16

    How do I find out which application plays sound?

  17. 17

    How do I find out which application is disabling sleep?

  18. 18

    How do I find out which processes are preventing unmounting of a device?

  19. 19

    How do I find out which RPM was used to install PHP?

  20. 20

    How do I find out which application plays sound?

  21. 21

    How do I find out which package owns a file?

  22. 22

    How do I find out which GCC toolchain is installed?

  23. 23

    How do I find out programmatically which mode of Location is turned on?

  24. 24

    How do I find out which touchpad driver is being used?

  25. 25

    How do I find out which repository a package comes from?

  26. 26

    How do I find out which process is preventing a umount?

  27. 27

    How do I show text and a button? (android)

  28. 28

    How do I find out how my currently Linux kernel was configured

  29. 29

    How do I find the area in which the camera field of view encompasses?

HotTag

Archive