Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple row Radio buttons in android?

Tags:

People also ask

Can we select multiple radio buttons Android?

To create each radio button option, create a RadioButton in your layout. However, because radio buttons are mutually exclusive, you must group them together inside a RadioGroup . By grouping them together, the system ensures that only one radio button can be selected at a time.

Can you have multiple radio buttons?

Only one radio button in a group can be selected at the same time. Note: The radio group must have share the same name (the value of the name attribute) to be treated as a group.

What is used to group together one or more radio buttons in Android?

A RadioGroup class is used for set of radio buttons. If we check one radio button that belongs to a radio group, it automatically unchecks any previously checked radio button within the same group.

How do I make a group of radio buttons?

You group radio buttons by drawing them inside a container such as a Panel control, a GroupBox control, or a form. All radio buttons that are added directly to a form become one group. To add separate groups, you must place them inside panels or group boxes.


I am having problem in having radioButtons in multiple Rows

this is my xml

           <RadioGroup android:layout_width="fill_parent"
               android:layout_height="wrap_content"
                android:orientation="vertical"
                 >
  <RadioGroup android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
         >
      <RadioButton
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:id="@+id/radio_one0Id"
          android:textSize="13sp"
          android:layout_weight="1"
          android:onClick="oneRadioButtonClicked"
       />
      <RadioButton
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
            android:textSize="13sp"
          android:text="5%" 
          android:id="@+id/radio_one5Id"
          android:layout_weight="1"
          android:onClick="oneRadioButtonClicked"
         />
      <RadioButton
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="10%" 
          android:textSize="13sp"
          android:layout_weight="1"
          android:id="@+id/radio_one10Id"
          android:onClick="oneRadioButtonClicked"
       />
      <RadioButton
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="20%" 
          android:layout_weight="1"
          android:textSize="13sp"
          android:onClick="oneRadioButtonClicked"
          android:id="@+id/radio_one20Id"
         />
      <RadioButton
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="35%" 
          android:id="@+id/radio_one35Id"
          android:textSize="13sp"
          android:onClick="oneRadioButtonClicked"
          android:layout_weight="1"
       />
      <RadioButton
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="50%" 
          android:textSize="13sp"
          android:id="@+id/radio_one50Id"
          android:onClick="oneRadioButtonClicked"
          android:layout_weight="1"
         />

      </RadioGroup>

        <RadioGroup android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
         <RadioButton
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="65%" 
          android:textSize="13sp"
          android:id="@+id/radio_one65Id"
          android:onClick="oneRadioButtonClicked"
          android:layout_weight="1"
       />
      <RadioButton
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="75%" 
          android:textSize="13sp"
          android:layout_weight="1"
          android:id="@+id/radio_one75Id"
          android:onClick="oneRadioButtonClicked"
         />
       <RadioButton
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="85%" 
          android:textSize="13sp"
          android:id="@+id/radio_one85Id"
          android:layout_weight="1"
          android:onClick="oneRadioButtonClicked"
         />
        <RadioButton
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
         android:textSize="13sp"
          android:text="95%" 
          android:id="@+id/radio_one95Id"
          android:layout_weight="1"
          android:onClick="oneRadioButtonClicked"
         />
         <RadioButton
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="100%" 
          android:id="@+id/radio_one100Id"
          android:textSize="13sp"
          android:layout_weight="1"
          android:onClick="oneRadioButtonClicked"
         />
                       </RadioGroup>
      </RadioGroup>

this is code

public void oneRadioButtonClicked(View view) {
    // Is the button now checked?
    boolean checked = ((RadioButton) view).isChecked();

    switch(view.getId()) {
        case R.id.radio_one0Id:
            if (checked)
                one = "0";
            break;
        case R.id.radio_one5Id:
            if (checked)
                one = "5";
            break;
        case R.id.radio_one10Id:
            if (checked)
                one = "10";
            break;
        case R.id.radio_one20Id:
            if (checked)
                one = "20";
            break;
        case R.id.radio_one35Id:
            if (checked)
                one = "35";
            break;
        case R.id.radio_one50Id:
            if (checked)
                one = "50";
            break;
        case R.id.radio_one65Id:
            if (checked)
                one = "65";
            break;
        case R.id.radio_one75Id:
            if (checked)
                one = "75";
            break;
        case R.id.radio_one85Id:
            if (checked)
                one = "85";
            break;
        case R.id.radio_one95Id:
            if (checked)
                one = "95";
            break;
        case R.id.radio_one100Id:
            if (checked)
                one = "100";
            break;
         default:
             System.out.println("default");
    }
}

this will look likeenter image description here

it will select both the buttons in 2 rows, i want it to select only one button in those rows, thanks for any help