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
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);
add a comment |
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);
add a comment |
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);
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);
edited Mar 7 at 18:49
Zoe
12.6k74884
12.6k74884
asked Mar 7 at 18:43
MarioCasMarioCas
12
12
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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