Android Open Source - Books Edit Or Delete Dialog Fragment






From Project

Back to project page Books.

License

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.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
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;

  @Override
  public void onAttach(Activity activity) {
    super.onAttach(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");
    }
  }


  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setMessage(R.string.dialog_edit_or_delete);
    builder.setPositiveButton(R.string.dialog_edit, new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int id) {
        mListener.onDialogEditClick(EditOrDeleteDialogFragment.this);
      }
    });
    builder.setNegativeButton(R.string.dialog_delete, new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int id) {
        // Delete entry
        mListener.onDialogDeleteClick(EditOrDeleteDialogFragment.this);
      }
    });

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

  }
}




Java Source Code List

com.contender.books.BookActivity.java
com.contender.books.BooksStorage.java
com.contender.books.DatePickerFragment.java
com.contender.books.EditOrDeleteDialogFragment.java
com.contender.books.HistoryActivity.java
com.contender.books.MainView.java
com.contender.books.ScanOrManualDialogFragment.java
com.contender.books.SettingsActivity.java
com.contender.books.SpecialCursorAdapter.java
com.google.zxing.integration.android.IntentIntegrator.java
com.google.zxing.integration.android.IntentResult.java