How to setChecked ImageView on AndroidStudio2019 Community Moderator ElectionHow do save an Android Activity state using save instance state?How do I center text horizontally and vertically in a TextView?Why is the Android emulator so slow? How can we speed up the Android emulator?How to make an ImageView with rounded corners?How to load an ImageView by URL in Android?How to scale an Image in ImageView to keep the aspect ratioSet ImageView width and height programmatically?How do I fix android.os.NetworkOnMainThreadException?setText on button from another activity androidHow to read temperature from ti SensorTag Android

Unfrosted light bulb

How do researchers send unsolicited emails asking for feedback on their works?

Why doesn't the chatan sign the ketubah?

Was World War I a war of liberals against authoritarians?

What is the difference between something being completely legal and being completely decriminalized?

What are the rules for concealing thieves' tools (or items in general)?

Do I need an EFI partition for each 18.04 ubuntu I have on my HD?

Why is this tree refusing to shed its dead leaves?

Exposing a company lying about themselves in a tightly knit industry: Is my career at risk on the long run?

What is the tangent at a sharp point on a curve?

What will the Frenchman say?

How do you justify more code being written by following clean code practices?

"Marked down as someone wanting to sell shares." What does that mean?

Asserting that Atheism and Theism are both faith based positions

is this saw blade faulty?

Why does Surtur say that Thor is Asgard's doom?

Why doesn't the fusion process of the sun speed up?

Why I don't get the wanted width of tcbox?

What is it called when someone votes for an option that's not their first choice?

What are the differences between tunneling and regulare encapsulation?

Would this string work as string?

Is VPN a layer 3 concept?

Single word to change groups

Hackerrank All Women's Codesprint 2019: Name the Product



How to setChecked ImageView on AndroidStudio



2019 Community Moderator ElectionHow do save an Android Activity state using save instance state?How do I center text horizontally and vertically in a TextView?Why is the Android emulator so slow? How can we speed up the Android emulator?How to make an ImageView with rounded corners?How to load an ImageView by URL in Android?How to scale an Image in ImageView to keep the aspect ratioSet ImageView width and height programmatically?How do I fix android.os.NetworkOnMainThreadException?setText on button from another activity androidHow to read temperature from ti SensorTag Android










0















I'm working with the CC2640 of Texas Instruments and my custom app. Everything works perfectly, but I discovered a bug. In practice, from the app I can read the status of the inputs of my devices, so if they are free (green light) if they are busy (red light). At this time are set as Settogglebutton, but I do not want in the layout as a button but as images that change to the true/False value. How can I do that? This is my part of code:



 if (intent.hasExtra(MainActivity.EXTRA_INPUT1)) 
setToggleButtonState(R.id.ingresso, intent.getIntExtra(MainActivity.EXTRA_INPUT1, 0));
else if (intent.hasExtra(MainActivity.EXTRA_INPUT2))
setToggleButtonState(R.id.ingresso2, intent.getIntExtra(MainActivity.EXTRA_INPUT2, 0));


private void setToggleButtonState(int id, int value)
if (id != -1)
final ToggleButton b = (ToggleButton) findViewById(id);
if(value == 1)
b.setChecked(true);

else
b.setChecked(false);













share|improve this question




























    0















    I'm working with the CC2640 of Texas Instruments and my custom app. Everything works perfectly, but I discovered a bug. In practice, from the app I can read the status of the inputs of my devices, so if they are free (green light) if they are busy (red light). At this time are set as Settogglebutton, but I do not want in the layout as a button but as images that change to the true/False value. How can I do that? This is my part of code:



     if (intent.hasExtra(MainActivity.EXTRA_INPUT1)) 
    setToggleButtonState(R.id.ingresso, intent.getIntExtra(MainActivity.EXTRA_INPUT1, 0));
    else if (intent.hasExtra(MainActivity.EXTRA_INPUT2))
    setToggleButtonState(R.id.ingresso2, intent.getIntExtra(MainActivity.EXTRA_INPUT2, 0));


    private void setToggleButtonState(int id, int value)
    if (id != -1)
    final ToggleButton b = (ToggleButton) findViewById(id);
    if(value == 1)
    b.setChecked(true);

    else
    b.setChecked(false);













    share|improve this question


























      0












      0








      0








      I'm working with the CC2640 of Texas Instruments and my custom app. Everything works perfectly, but I discovered a bug. In practice, from the app I can read the status of the inputs of my devices, so if they are free (green light) if they are busy (red light). At this time are set as Settogglebutton, but I do not want in the layout as a button but as images that change to the true/False value. How can I do that? This is my part of code:



       if (intent.hasExtra(MainActivity.EXTRA_INPUT1)) 
      setToggleButtonState(R.id.ingresso, intent.getIntExtra(MainActivity.EXTRA_INPUT1, 0));
      else if (intent.hasExtra(MainActivity.EXTRA_INPUT2))
      setToggleButtonState(R.id.ingresso2, intent.getIntExtra(MainActivity.EXTRA_INPUT2, 0));


      private void setToggleButtonState(int id, int value)
      if (id != -1)
      final ToggleButton b = (ToggleButton) findViewById(id);
      if(value == 1)
      b.setChecked(true);

      else
      b.setChecked(false);













      share|improve this question
















      I'm working with the CC2640 of Texas Instruments and my custom app. Everything works perfectly, but I discovered a bug. In practice, from the app I can read the status of the inputs of my devices, so if they are free (green light) if they are busy (red light). At this time are set as Settogglebutton, but I do not want in the layout as a button but as images that change to the true/False value. How can I do that? This is my part of code:



       if (intent.hasExtra(MainActivity.EXTRA_INPUT1)) 
      setToggleButtonState(R.id.ingresso, intent.getIntExtra(MainActivity.EXTRA_INPUT1, 0));
      else if (intent.hasExtra(MainActivity.EXTRA_INPUT2))
      setToggleButtonState(R.id.ingresso2, intent.getIntExtra(MainActivity.EXTRA_INPUT2, 0));


      private void setToggleButtonState(int id, int value)
      if (id != -1)
      final ToggleButton b = (ToggleButton) findViewById(id);
      if(value == 1)
      b.setChecked(true);

      else
      b.setChecked(false);










      android bluetooth-lowenergy






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 7 at 18:49









      Zoe

      12.6k74884




      12.6k74884










      asked Mar 7 at 18:43









      MarioCasMarioCas

      12




      12






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Let me see if i understood you correctly.
          You want to change an ImageView resource according to the value?



          private void setImageResource(int id, int value) {
          if (id != -1)
          final ImageView myImageView = (ImageView)findViewById(id); // i assume you wont use this imageview anywhere else, you just want to change the resource.
          if(value == 1)
          myImgView.setImageResource(R.drawable.true);

          else
          myImgView.setImageResource(R.drawable.false);





          If you want the imageview to save the value, you could define it as an attribute and save it in the image tag.






          share|improve this answer























          • Thanks!! It works!

            – MarioCas
            Mar 7 at 19:30











          • Great! can you mark it as accepted answer? Thank you

            – Agustin Pazos
            Mar 8 at 14:20











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55050766%2fhow-to-setchecked-imageview-on-androidstudio%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Let me see if i understood you correctly.
          You want to change an ImageView resource according to the value?



          private void setImageResource(int id, int value) {
          if (id != -1)
          final ImageView myImageView = (ImageView)findViewById(id); // i assume you wont use this imageview anywhere else, you just want to change the resource.
          if(value == 1)
          myImgView.setImageResource(R.drawable.true);

          else
          myImgView.setImageResource(R.drawable.false);





          If you want the imageview to save the value, you could define it as an attribute and save it in the image tag.






          share|improve this answer























          • Thanks!! It works!

            – MarioCas
            Mar 7 at 19:30











          • Great! can you mark it as accepted answer? Thank you

            – Agustin Pazos
            Mar 8 at 14:20
















          0














          Let me see if i understood you correctly.
          You want to change an ImageView resource according to the value?



          private void setImageResource(int id, int value) {
          if (id != -1)
          final ImageView myImageView = (ImageView)findViewById(id); // i assume you wont use this imageview anywhere else, you just want to change the resource.
          if(value == 1)
          myImgView.setImageResource(R.drawable.true);

          else
          myImgView.setImageResource(R.drawable.false);





          If you want the imageview to save the value, you could define it as an attribute and save it in the image tag.






          share|improve this answer























          • Thanks!! It works!

            – MarioCas
            Mar 7 at 19:30











          • Great! can you mark it as accepted answer? Thank you

            – Agustin Pazos
            Mar 8 at 14:20














          0












          0








          0







          Let me see if i understood you correctly.
          You want to change an ImageView resource according to the value?



          private void setImageResource(int id, int value) {
          if (id != -1)
          final ImageView myImageView = (ImageView)findViewById(id); // i assume you wont use this imageview anywhere else, you just want to change the resource.
          if(value == 1)
          myImgView.setImageResource(R.drawable.true);

          else
          myImgView.setImageResource(R.drawable.false);





          If you want the imageview to save the value, you could define it as an attribute and save it in the image tag.






          share|improve this answer













          Let me see if i understood you correctly.
          You want to change an ImageView resource according to the value?



          private void setImageResource(int id, int value) {
          if (id != -1)
          final ImageView myImageView = (ImageView)findViewById(id); // i assume you wont use this imageview anywhere else, you just want to change the resource.
          if(value == 1)
          myImgView.setImageResource(R.drawable.true);

          else
          myImgView.setImageResource(R.drawable.false);





          If you want the imageview to save the value, you could define it as an attribute and save it in the image tag.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 7 at 19:03









          Agustin PazosAgustin Pazos

          515




          515












          • Thanks!! It works!

            – MarioCas
            Mar 7 at 19:30











          • Great! can you mark it as accepted answer? Thank you

            – Agustin Pazos
            Mar 8 at 14:20


















          • Thanks!! It works!

            – MarioCas
            Mar 7 at 19:30











          • Great! can you mark it as accepted answer? Thank you

            – Agustin Pazos
            Mar 8 at 14:20

















          Thanks!! It works!

          – MarioCas
          Mar 7 at 19:30





          Thanks!! It works!

          – MarioCas
          Mar 7 at 19:30













          Great! can you mark it as accepted answer? Thank you

          – Agustin Pazos
          Mar 8 at 14:20






          Great! can you mark it as accepted answer? Thank you

          – Agustin Pazos
          Mar 8 at 14:20




















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55050766%2fhow-to-setchecked-imageview-on-androidstudio%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

          List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229