0

I am working on a simple converter between Decimal/Hex/Binary and have run into an issue I can't seem to solve. This is the layout I am more or less aiming for.

enter image description here

What I am here is when one of the buttons is pressed, it stays pressed to indicate which conversion you are currently working with. Now I have looked everywhere and it doesn't seem there is a good way of doing this, or I haven't found it at least.

What would be the best way to go about this? is there someway to just use buttons and have them stay in their "pressed" state when they are clicked? By this I only need the color of the pressed button to show. Or is there a way of doing this with some type of radio group, where the radio buttons have the same style as a regular button?

Scalahansolo
  • 2,615
  • 6
  • 26
  • 43

1 Answers1

1

Try:

button.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {

        ... do a call to your conversion code here ....

        button.setPressed(true);
        return true;
    }
});

For more info: Android docs and this SO question

Community
  • 1
  • 1
Tigger
  • 8,980
  • 5
  • 36
  • 40
  • Is there anyway to do something like this, but have it so that I don't lose the setPressed after the method ends? – Scalahansolo Sep 05 '13 at 03:36
  • @SeanCallahan The `button` should stay in the pressed state until the `Activity` is reload or you make a `button.setPressed(false)` call. What have you tried? – Tigger Sep 05 '13 at 03:40
  • @Trigger That works actually! This is great. One last question you might be able to help me with. Is there anyway to check if the button is in a pressed state somewhere else in my code? – Scalahansolo Sep 05 '13 at 03:46
  • @SeanCallahan Sure, as the [developer docs says](http://developer.android.com/reference/android/view/View.html#isPressed%28%29) - you can use `button.isPressed()` – Tigger Sep 05 '13 at 04:10