0% found this document useful (0 votes)
94 views3 pages

Todo: Update Blank Fragment Layout: Textview

The document contains code for an Android fragment that displays a dialog with radio button options to select a favorite food. It includes layout XML with TextViews and RadioButtons for different food options. The OptionDialogFragment class finds the radio group and buttons, sets an onclick listener to close or choose an option, and notifies the listener of the chosen option.

Uploaded by

shelo laitera
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
94 views3 pages

Todo: Update Blank Fragment Layout: Textview

The document contains code for an Android fragment that displays a dialog with radio button options to select a favorite food. It includes layout XML with TextViews and RadioButtons for different food options. The OptionDialogFragment class finds the radio group and buttons, sets an onclick listener to close or choose an option, and notifies the listener of the chosen option.

Uploaded by

shelo laitera
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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);
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy