Back to project page MythTrack.
The source code is released under:
MIT License
If you think the Android project MythTrack listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/** * DeleteHeroDialog confirms a user's choice to delete a hero. *//from www . j a v a 2s. com * @author Nolan Jurgens */ package nolanjurgens.mythtrack.app; // IMPORTS ///////////////////////////////////////////////////////////////////////////////////////// import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.app.DialogFragment; import android.content.DialogInterface; import android.os.Bundle; import nolanjurgens.mythtrack.R; //////////////////////////////////////////////////////////////////////////////////////////////////// // CLASS - DeleteHeroDialog // //////////////////////////////////////////////////////////////////////////////////////////////////// public class DeleteHeroDialog extends DialogFragment { // INTERFACES //////////////////////////////////////////////////////////////////////////////////// /** Interface for listener for when a hero is deleted.*/ OnDeleteHeroConfirmationListener callback; public interface OnDeleteHeroConfirmationListener { public void onDeleteHeroConfirmed(long heroID); } // METHODS /////////////////////////////////////////////////////////////////////////////////////// /** * Called when the fragment is attached to the activity. * @param activity The host activity. */ @Override public void onAttach(Activity activity) { super.onAttach(activity); // Make sure the host activity implements the interface. try { callback = (OnDeleteHeroConfirmationListener) activity; } catch(ClassCastException exception) { throw new ClassCastException(activity.toString() + " must implement onDeleteHeroConfirmed"); } } /** * Called when the dialog is to be created. * @param arguments Arguments for the dialog. * @return The created dialog. */ @Override public Dialog onCreateDialog(Bundle arguments) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Set the title. builder.setTitle(R.string.deleteherodialog_title); // Set the message. String deleteMessage = getArguments().getString("name") + " - " + getArguments().getString("class") + " " + getString(R.string.deleteherodialog_message); builder.setMessage(deleteMessage); // Set up the "Delete" button and its action. builder.setPositiveButton(R.string.deleteherodialog_positive, new DialogInterface.OnClickListener() { /** * Handle the "Delete" button being clicked. * @param dialogInterface The dialog being handled. * @param button Which button was clicked. */ @Override public void onClick(DialogInterface dialogInterface, int button) { // Delete the hero via the activity. callback.onDeleteHeroConfirmed(getArguments().getLong("id")); } }); // Set up the "Cancel" button and its action. builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { /** * Handle the "Cancel" button being clicked. * @param dialogInterface The dialog being handled. * @param button Which button was clicked. */ @Override public void onClick(DialogInterface dialogInterface, int button) { // Just exit the dialog. } }); return builder.create(); } }