I want to create a custom Checkbox with four different states:
- Unchecked (an empty checkbox)
- Checked (a green check)
- Unavailable (a red cross)
- Partly unavailable (an orange check)
I did found here how to create a checkbox with custom images (with the states pressed, focused, hovered and default). But what I want instead is a way to cycle between the four states as follows:
- press once: it's green checked;
- press twice: it's a red cross;
- price thrice: it's orange checked;
- press four times: it's unchecked again.
PS: I know it's probably easier in an android app to just make a dropdown with the 4 states or a pop-up where you select one of the states. But I want among these two, this third option above, so users can decide for themselves which of the three settings they'll prefer.
PSS: While I'm typing this I came up with the idea of a button with the unchecked image, and when you click it it will replace the image-src to the next, while keeping everything else the same (like width/height and margin/padding). Is this the best approach for this situation, or does someone have a more elegant solution instead?
Thanks in advance for the responses.
As stated in the PSS, I only had the idea for the solution when I was typing the question above. I've used an ImageButton that changes it's source when it's clicked. Here is the code:
ImageButton in xml:
transparent_button_background.xml:
Activity: