0

Remember when we used tabs, then pressing on one tab would turn that tab ON and all other tabs OFF.

Now, imagine 4 buttons in the middle of an Activity which represent tabs. Clicking on each buttons will turn that button to ON state, and all others to OFF state, and will accordingly load a fragment below these 4 buttons.

Right now, I have coded these buttons' states via foreach loop where I set the button states.

Is there a better way to do it? Something like RadioGroup and RadioButton where setting states is done automatically.

sandalone
  • 41,141
  • 63
  • 222
  • 338
  • 2
    So, basically, it's a RadioGroup with **custom RadioButtons** (i.e.: without the "circle"). – Phantômaxx Nov 06 '14 at 18:28
  • 1
    [ToggleButttons](http://developer.android.com/reference/android/widget/ToggleButton.html)? [This may also help](http://stackoverflow.com/questions/22186523/how-do-i-make-my-toggle-button-act-like-a-radio-button/22186545#22186545) – codeMagic Nov 06 '14 at 18:30
  • 1
    Yes, you can remove the button. See this: http://stackoverflow.com/questions/19163628/adding-custom-radio-buttons-in-android - The accepted answer seems just perfect. – Phantômaxx Nov 06 '14 at 18:31
  • Guys, you are right. Silly question and silly me. – sandalone Nov 06 '14 at 18:33

1 Answers1

0

Take a look at android swipe view tab layout example! This code cycles among fragments (activities) based on which tab is pressed. Is this what you're looking for?

Please note that tabhost, another way of setting up tabs, is depricated.

Minesweep
  • 13
  • 4