2

I am currently using an ImageButton, and I want to have the effect like radio button once you select it stays selected, until someone picks another image button. I have setup custom selector like below:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:state_pressed="true"
           android:drawable="@drawable/buttonimagesel" /> <!-- pressed -->
     <item android:state_focused="true"
           android:drawable="@drawable/buttonimagesel" /> <!-- focused -->
     <item android:drawable="@drawable/buttonimage" /> <!-- default -->
</selector>

But this just shows the selected image for as long as the key is pressed down. The effect i want is for it to stay selected like a radio button until the request is processed after which the whole activity including the button is redrawn. So I want one click to put the button in a selected state and unclick does not change this. Also I do not want the other buttons to be selectable after this happens, and I don't certainly don't want them to change images or anything like that.

Thanks

bigstones
  • 15,087
  • 7
  • 65
  • 82
Androider
  • 21,125
  • 36
  • 99
  • 158

1 Answers1

5

If you need to use an ImageButton, you can add an android:state_selected="true" item and use setSelected() in your onClick() logic. You would have to take care of deselecting all the other buttons when selecting a new one. This question might be useful: Android ImageButton with a selected state?

However you could also just use RadioButtons and customize their look (with android:background and android:button - these and all CompoundButtons have a checked state that work in a toggling way).

Community
  • 1
  • 1
bigstones
  • 15,087
  • 7
  • 65
  • 82