- <RadioGroup
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- android:layout_marginLeft="0dp"
- android:id="@+id/sell_category_radiogroup">
- <RadioButton
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:checked="false"
- android:id="@+id/sell_radio_classic"
- android:text="classic" />
- <RadioButton
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:checked="false"
- android:id="@+id/sell_radio_enduro"
- android:text="enduro" />
- <RadioButton
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:checked="false"
- android:id="@+id/sell_radio_bigbike"
- android:text="bigbike" />
- <RadioButton
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:checked="false"
- android:id="@+id/sell_radio_other"
- android:text="other" />
- </RadioGroup>
MainActivity.java
- RadioGroup radioGroup = (RadioGroup)findViewById(R.id.sell_category_radiogroup);
- radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(RadioGroup group, int checkedId) {
- RadioButton radioButton = (RadioButton) group.findViewById(checkedId);
- if (radioButton.getText().toString().equals("classic")) {
- Log.e("radio : ", "classic");
- } else if (radioButton.getText().toString().equals("enduro")) {
- Log.e("radio : ", "enduro");
- } else if (radioButton.getText().toString().equals("bigbike")) {
- Log.e("radio : ", "bigbike");
- } else if (radioButton.getText().toString().equals("other")) {
- Log.e("radio : ", "other");
- }
- }
- });