Я новичок в Android Studio. Я не знаю, как решить мою проблему. Есть фрагмент, который я бы хотел, чтобы пользователь выбирал то, что ему нравится, в Radio Group, у которой есть три переключателя. Перед тем, как отправить свой результат В другом фрагменте мне нужно открыть диалоговое окно Alert, чтобы пользователь снова мог проверить, что он выбрал. Можно ли как-нибудь собрать результат всех кнопок и показать его пользователям?
public class MainActivity extends Fragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.radio_button, container, false);
RadioGroup rgdSize = view.findViewById(R.id.rdgSize);
rgdSize.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
switch (i) {
case (R.id.rdbSmall):
break;
case (R.id.rdbMedium):
break;
case (R.id.rdbLarge):
break;
}
}
});
RadioGroup rgdRank = view.findViewById(R.id.rdgRank);
rgdRank.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
switch (i) {
case (R.id.rdbFirst):
break;
case (R.id.rdbSecond):
break;
case (R.id.rdbThird):
break;
}
}
});
Button btnSend;
btnSend = view.findViewById(R.id.btnSend);
btnSend.setOnClickListener(btnSendListener);
return view;
}
private Button.OnClickListener btnSendListener = new Button.OnClickListener(){
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.btnSend:
new AlertDialog.Builder(getActivity())
.setTitle("Please make sure you choose correct")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.show();
}
}
};
}
Вот мой XML
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/rdgSize">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Size"
android:textSize="40sp"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Small"
android:textSize="20sp"
android:id="@+id/rdbSmall"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium"
android:textSize="20sp"
android:id="@+id/rdbMedium"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large"
android:textSize="20sp"
android:id="@+id/rdbLarge"/>
</RadioGroup>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintTop_toBottomOf="@+id/rdgSize"
android:id="@+id/rdgRank">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"
android:text="Rank"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First"
android:textSize="20sp"
android:id="@+id/rdbFirst"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Second"
android:textSize="20sp"
android:id="@+id/rdbSecond"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Third"
android:textSize="20sp"
android:id="@+id/rdbThird"/>
</RadioGroup>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/rdgRank"
android:text="Send"
android:id="@+id/btnSend"/>