Trying hard challenge... 3 button AlertDialog


#1

I thought I’d try the hard challenge. My approach was to use a 3-button alert dialog (below in CrimeFragment). However what happens, and I think I can see why, is that the alert flashes up, and then the date picker flashes. Once I click OK on the date picker then I see my 3-button alert again and it awaits my input. Right now the 3 buttons are effective null with the exception of Log statements

Is there a way for it not to continue through the code to display the date picker until a response to the 3-button alert is selected?

Also, and I dont know why, if you notice I have 3 Log statements, none of which show up when I click on the appropriate alert buttons. So that tells me it’s not going through the code, but the alert dialog box is up.

mDateButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Use 3 button AlertDialog to see what the user wishes to edit
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());

				alertDialogBuilder.setTitle("Edit Date or Time");
	 
				// set dialog message
				alertDialogBuilder
					.setCancelable(false)
					.setPositiveButton("Exit",new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog,int id) {
                            Log.d("DATE_TIME", "User selected to edit date");
							dialog.cancel();
						}
					  })
					.setNegativeButton("Date",new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog,int id) {  // edit Time
                            Log.d("DATE_TIME", "User selected to edit time");
							dialog.cancel();
						}
					})
					.setNeutralButton("Time",new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog,int id) {
                            Log.d("DATE_TIME", "User selected to Exit");
							dialog.cancel();
						}
					});
	 
					// create alert dialog
					AlertDialog alertDialog = alertDialogBuilder.create();
	 
					// show it
					alertDialog.show();
			FragmentManager fm = getActivity()

#2

You are starting your chooser dialog in the right place but the time picker and date picker dialogs should be started in CrimeFragment.onActivityResult(). That removes the need for you to wait for the user to respond to the dialog. Also, you can get by with two buttons since Android sort of has a built in cancel button (the u-turn arrow).