Radio Button
activity_main.xml <androidx.constraintlayout.widget.ConstraintLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” xmlns:tools=”http://schemas.android.com/tools” android:layout_width=”match_parent” android:layout_height=”match_parent” tools:context=”.MainActivity”> <RadioGroup android:id=”@+id/rg_gender” android:layout_width=”wrap_content” android:layout_height=”wrap_content” app:layout_constraintBottom_toBottomOf=”parent” app:layout_constraintEnd_toEndOf=”parent” app:layout_constraintStart_toStartOf=”parent” app:layout_constraintTop_toTopOf=”parent” > <RadioButton android:id=”@+id/rb_man” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:text=”남자” /> <RadioButton android:id=”@+id/rb_woman” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:text=”여자” /> </RadioGroup> <Button android:id=”@+id/btn_result” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_marginTop=”50dp” android:text=”결과 버튼” app:layout_constraintEnd_toEndOf=”parent” app:layout_constraintStart_toStartOf=”parent” app:layout_constraintTop_toBottomOf=”@+id/rg_gender” /> </androidx.constraintlayout.widget.ConstraintLayout> MainActivity.java public class MainActivity extends AppCompatActivity { private RadioGroup rg_gender; private RadioButton rb_man, rb_woman; private Button btn_result; private String str_result; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); rg_gender = findViewById(R.id.rg_gender); // 라디오 버튼들을 담고있는 그룹 rb_man =…
Read More