Android Open Source - Books Edit Or Delete Dialog Fragment

From Project

Back to project page Books.


The source code is released under:

Apache License

If you think the Android project Books listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.contender.books;
//from   w w w  .  j a  v a2  s .c  om
import android.content.DialogInterface;
import android.os.Bundle;

 * Implements the EditOrDeleteDialogFragment dialog used by {@link MainView}
 * <p>
 * Inquires if the user wants to edit or delete the selected item from the ListView.
 * @author Paul Klinkenberg
public class EditOrDeleteDialogFragment extends DialogFragment {

  /* The activity that creates an instance of this dialog fragment must
   * implement this interface in order to receive event callbacks.
   * Each method passes the DialogFragment in case the host needs to query it. */
  public interface EditOrDeleteDialogListener {
    public void onDialogEditClick(DialogFragment dialog);
    public void onDialogDeleteClick(DialogFragment dialog);

  // Use this instance of the interface to deliver action events
  EditOrDeleteDialogListener mListener;

  public void onAttach(Activity activity) {
    // Verify that the host activity implements the callback interface
    try {
      mListener = (EditOrDeleteDialogListener) activity;
    } catch (ClassCastException e) {
      throw new ClassCastException(activity.toString() + " must implement EditOrDeleteDialogListener");

  public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setPositiveButton(R.string.dialog_edit, new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int id) {
    builder.setNegativeButton(R.string.dialog_delete, new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int id) {
        // Delete entry

    // Create the AlertDialog object and return it
    return builder.create();


Java Source Code List