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

          Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

          Posting a File and Associated Data to a RESTful WebService preferably as JSON2019 Community Moderator ElectionREST URI convention - Singular or plural name of resource while creating itUploading both data and files in one form using Ajax?How do I upload a file with metadata using a REST web service?REST API - file (ie images) processing - best practicesSpring: JSON data and file in the same requestREST API Put large dataPosting a file and JSON data to Spring rest serviceRESTful Web Service Upload/Download Large Data With JSONREST API Design sending JSON data and a file to the api in same requestPost JSONArray to REST servicePUT vs. POST in RESTParsing values from a JSON file?JavaScript/jQuery to download file via POST with JSON dataHow do I upload a file with metadata using a REST web service?How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?Separate REST JSON API server and client?what's the correct way to send a file from REST web service to client?How do I write JSON data to a file?What is “406-Not Acceptable Response” in HTTP?REST API - file (ie images) processing - best practices

          How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page