【发布时间】:2020-06-12 14:28:03
【问题描述】:
我正在 android 中创建一个要求性别的表单。要获得此输入,我使用包含两个按钮的 Material Button Toggle Group。我不知道如何知道在我的activity.java 中单击了哪个按钮。如何了解我的活动中选定的按钮,以便我可以将详细信息保存在不同的数据库中。
myxml.xml
<com.google.android.material.button.MaterialButtonToggleGroup
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:singleSelection="true">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:layout_marginStart="5dp"
style="?attr/materialButtonOutlinedStyle"/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:layout_marginStart="10dp"
style="?attr/materialButtonOutlinedStyle"/>
</com.google.android.material.button.MaterialButtonToggleGroup>
Myactivity.java
MaterialButtonToggleGroup toggleButton = findViewById(R.id.toggleButton);
toggleButton.addOnButtonCheckedListener();
// I CAN'T FIND ANY PROPER SOLUTION
【问题讨论】:
标签: java android android-layout android-button material-components-android