コード例 #1
0
  private void showDeleteDialog() {
    Log.d(TAG, "showDeleteDialog() called");

    final Dialog deleteDialog = new Dialog(NoteActivity.this);
    LinearLayout dialogLayout =
        (LinearLayout) View.inflate(NoteActivity.this, R.layout.delete_note_dialog, null);
    deleteDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    deleteDialog.setContentView(dialogLayout);

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(deleteDialog.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.MATCH_PARENT;

    deleteDialog.show();
    deleteDialog.getWindow().setAttributes(lp);

    TextView noteTitleTextView =
        (TextView) dialogLayout.findViewById(R.id.delete_note_dialog_delete_note_title_textview);
    noteTitleTextView.setText(note.getTitle());

    Button confirmDeleteButton =
        (Button) dialogLayout.findViewById(R.id.delete_note_dialog_confirm_button);
    confirmDeleteButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Log.d(TAG, "Delete dialog confirm button clicked");
            noteProvider.deleteNote(note);
            finish();
          }
        });

    Button cancelDeleteButton =
        (Button) dialogLayout.findViewById(R.id.delete_note_dialog_cancel_button);
    cancelDeleteButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Log.d(TAG, "Delete dialog cancel button clicked");
            deleteDialog.dismiss();
          }
        });
  }