Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Android Studio help with creating Custom Dialog with Radio Group buttons. I created the layout but none of the buttons work. Link to demo video

Android Studio help with creating Custom Dialog with Radio Group buttons. I created the layout but none of the buttons work. Link to demo video below. Thanks

https://www.youtube.com/watch?v=FjYVt0nVvVo&feature=youtu.be

My Code for WorkFragment.java below

public class WorkFragment extends Fragment { // TODO: Rename parameter arguments, choose names that match  // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER  private static final String ARG_PARAM1 = "param1"; private static final String ARG_PARAM2 = "param2"; // TODO: Rename and change types of parameters  private String mParam1; private String mParam2; public WorkFragment() { // Required empty public constructor  } /**  * Use this factory method to create a new instance of  * this fragment using the provided parameters.  *  * @param param1 Parameter 1.  * @param param2 Parameter 2.  * @return A new instance of fragment WorkFragment.  */  // TODO: Rename and change types and number of parameters  public static WorkFragment newInstance(String param1, String param2) { WorkFragment fragment = new WorkFragment(); Bundle args = new Bundle(); args.putString(ARG_PARAM1, param1); args.putString(ARG_PARAM2, param2); fragment.setArguments(args); return fragment; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mParam1 = getArguments().getString(ARG_PARAM1); mParam2 = getArguments().getString(ARG_PARAM2); } } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment  return inflater.inflate(R.layout.fragment_work, container, false); } } 

The XML code for my fragment_work.xml below

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"  xmlns:tools="http://schemas.android.com/tools"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:background="@android:color/black"    <RelativeLayout  android:layout_width="match_parent"  android:layout_height="match_parent"> <TextView  android:layout_width="match_parent"  android:layout_height="35dp"  android:textAlignment="center"  android:text="This fragment is used for quiz!"  android:textColor="@color/white"  android:background="@android:color/holo_blue_dark"  android:layout_alignParentTop="true"  android:layout_alignParentStart="true" /> <Button  android:id="@+id/button7"  android:layout_width="125dp"  android:layout_height="wrap_content"  android:layout_marginTop="41dp"  android:text="Quiz1"  android:layout_alignParentTop="true" /> <Button  android:id="@+id/button8"  android:layout_width="125dp"  android:layout_height="wrap_content"  android:layout_alignTop="@+id/button7"  android:layout_centerHorizontal="true"  android:text="Quiz2" /> <Button  android:id="@+id/button9"  android:layout_width="125dp"  android:layout_height="wrap_content"  android:layout_alignParentEnd="true"  android:layout_alignTop="@+id/button8"  android:text="Quiz3" /> <Button  android:id="@+id/button10"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_alignParentEnd="true"  android:layout_alignParentStart="true"  android:layout_below="@+id/button8"  android:layout_marginTop="13dp"  android:background="@android:color/holo_blue_bright"  android:backgroundTint="@android:color/holo_blue_dark"  android:text="Submit"  android:textSize="15sp" /> <TextView  android:id="@+id/textView6"  android:layout_width="match_parent"  android:layout_height="35dp"  android:layout_centerHorizontal="true"  android:text="You can do it!"  android:textColor="@android:color/white"  android:gravity="center"  android:background="@android:color/holo_blue_dark"  android:layout_alignParentBottom="true" /> RelativeLayout> FrameLayout> 

The XML code for the custom dialog custom_dialog_quiz3.xml

xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:orientation="vertical" android:layout_width="wrap_content"  android:layout_height="wrap_content"> <TextView  android:id="@+id/dialog_custom_title"  android:layout_width="match_parent"  android:layout_height="60dp"  android:text="Quiz3"  android:textSize="30sp"  android:textColor="@android:color/black"  android:background="@android:color/white"  android:gravity="center"/> <RadioButton  android:id="@+id/button_yes"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_below="@+id/dialog_custom_title"  android:text="Yes"/> <RadioButton  android:id="@+id/button_no"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_below="@+id/button_yes"  android:text="No"/> <RadioButton  android:id="@+id/button_exit"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_below="@+id/button_no"  android:text="Exit"/> <LinearLayout  android:id="@+id/activity_main_tool"  android:layout_width="match_parent"  android:layout_height="65dp"  android:orientation="horizontal"  android:layout_alignParentBottom="true"> <Button  android:id="@+id/button_cancel"  android:layout_width="0dp"  android:layout_height="match_parent"  android:text="Cancel"  android:textAllCaps="false"  android:layout_weight="3"  android:gravity="center"  android:layout_gravity="center_vertical"/> <Button  android:id="@+id/button_ok"  android:layout_width="0dp"  android:layout_height="match_parent"  android:text="OK"  android:layout_weight="3"  android:gravity="center"  android:layout_gravity="center_vertical"/> LinearLayout> RelativeLayout> 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 2 Lnai 9285

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Joao Gama ,Alipio Jorge ,Carlos Soares

1st Edition

3319235249, 978-3319235240

More Books

Students also viewed these Databases questions

Question

find all matrices A (a) A = 13 (b) A + A = 213

Answered: 1 week ago