Sie sind auf Seite 1von 3

android:orientation="vertical">

<!-- TODO: Update blank fragment layout -->


<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" Apa Makanan Kesukaanmu ??? "
android:layout_marginBottom="@dimen/activity_vertical_margin"/>

<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rg_options"
android:orientation="vertical">
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rb_siomay"
android:text="Siomay Bandung"
android:layout_marginBottom="@dimen/activity_vertical_margin"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rb_batagor"
android:text="Batagor"
android:layout_marginBottom="@dimen/activity_vertical_margin"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rb_rujak"
android:text="Rujak Cingur"
android:layout_marginBottom="@dimen/activity_vertical_margin"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rb_kupang"
android:text="Kupang"
android:layout_marginBottom="@dimen/activity_vertical_margin"/>
</RadioGroup>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:layout_marginRight="4dp"
android:id="@+id/btn_close"
android:text="Tutup"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btn_choose"
android:layout_weight="0.5"
android:layout_marginLeft="4dp"
android:text="Pilih"/>
</LinearLayout>
</LinearLayout>
public class OptionDialogFragment extends DialogFragment implements
View.OnClickListener {
private Button btnclose, btnChoose;
private RadioGroup rgOptions;
private RadioButton rbSiomay, rbBatagor, rbRujak, rbKupang;
private OnOptionDialogListener onOptionDialogListener;

public OptionDialogFragment() {
// Required empty public constructor
}

public OnOptionDialogListener getOnOptionDialogListener() {


return onOptionDialogListener;
}

public void setOnOptionDialogListener(OnOptionDialogListener


onOptionDialogListener) {
this.onOptionDialogListener = onOptionDialogListener;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_option_dialog2, container,
false);
btnclose = view.findViewById(R.id.btn_close);
btnclose.setOnClickListener(this);
btnChoose = view.findViewById(R.id.btn_choose);
btnChoose.setOnClickListener(this);
rgOptions = view.findViewById(R.id.rg_options);
rbSiomay = view.findViewById(R.id.rb_siomay);
rbBatagor = view.findViewById(R.id.rb_batagor);
rbRujak = view.findViewById(R.id.rb_rujak);
rbKupang = view.findViewById(R.id.rb_kupang);
return view;
}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_close:
getDialog().cancel();
break;
case R.id.btn_choose:
int checkedRadioButtonId = rgOptions.getCheckedRadioButtonId();
if (checkedRadioButtonId != -1) {
String food = null;
switch (checkedRadioButtonId) {
case R.id.rb_siomay:
food = rbSiomay.getText().toString().trim();
case R.id.rb_batagor:
food = rbBatagor.getText().toString().trim();
case R.id.rb_rujak:
food = rbRujak.getText().toString().trim();
case R.id.rb_kupang:
food = rbKupang.getText().toString().trim();
return;
}

getOnOptionDialogListener().onOptionChoosen(food);
getDialog().cancel();
break;
}
}
}

public interface OnOptionDialogListener {


void onOptionChoosen(String text);
}