单击复选框时如何添加确认框?

How to add confirm box when i click on checkbox?

我有两个动态复选框,一个用于删除视频,另一个用于保存 video.I 想添加一个确认框,以便在我单击 checkbox.How 添加时确认我的操作在我的代码中确认框?

deleteCheckBox.setOnClickListener(deleteRelatedThumbnail(deleteCheckBox));

 View.OnClickListener deleteRelatedThumbnail(final CheckBox checkBox) {

        return new View.OnClickListener() {
            public void onClick(View v) {
                int index = checkBox.getId();
                if (((CheckBox) v).isChecked() && deleteVideoFile(index - 1)){

                    // if(deleteVideoFile(index-1)){
                    bitMapsAvailable.remove(index - 1);
                    bitMapsFilePath.remove(index - 1);
                    Toast.makeText(MainActivity.this, "Selected video file is deleted successfully.", Toast.LENGTH_SHORT).show();
                    showThumbnails();
                }else{
                    Toast.makeText(MainActivity.this, "Not deleted", Toast.LENGTH_SHORT).show();
                }

            }
        };
    }





    saveCheckBox.setOnClickListener(saveRelatedThumbnail(saveCheckBox));
    View.OnClickListener saveRelatedThumbnail(final CheckBox checkBox) {

        return new View.OnClickListener() {
            public void onClick(View v) {
                int index = checkBox.getId()-31;
                if (((CheckBox) v).isChecked()){
                String src = bitMapsFilePath.get(index-1);
                String destination = mVideoFolder+"/"+new File(src).getName();

                File srcFile = new File(src);
                srcFile.renameTo(new File(destination));
                Toast.makeText(MainActivity.this, "Saved in "+destination, Toast.LENGTH_SHORT).show();
                bitMapsAvailable.clear();
                for(String filePath: bitMapsFilePath ) {
                    File file = new File(filePath);
                    file.delete();
                }
                bitMapsFilePath.clear();
                Toast.makeText(MainActivity.this, "Temporary videos are deleted successfully",Toast.LENGTH_SHORT).show();
                showThumbnails();
            }
        }
    };
    }

只是用户提醒对话框:

private void showLocationDialog() {  

AlertDialog.Builder builder = new AlertDialog.Builder(yOURActivity.this);
builder.setTitle(getString(R.string.dialog_title));
builder.setMessage(getString(R.string.dialog_message));

String positiveText = getString(android.R.string.ok);
builder.setPositiveButton(positiveText,
        new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        // positive button logic
    }
});

String negativeText = getString(android.R.string.cancel);
builder.setNegativeButton(negativeText,
        new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        // negative button logic
    }
});

AlertDialog dialog = builder.create();
// display dialog
dialog.show();

}

您可以使用警报对话框

    deleteCheckBox.setOnClickListener(deleteRelatedThumbnail(deleteCheckBox));

 View.OnClickListener deleteRelatedThumbnail(final CheckBox checkBox) {

        return new View.OnClickListener() {
            public void onClick(View v) {
                int index = checkBox.getId();
                if (((CheckBox) v).isChecked() && deleteVideoFile(index - 1)){
                    AlertDialog.Builder builder=new AlertDialog.Builder(MainActivity.this);// use you activity name
              builder.setMessage("Are you sure you want to delete? ")
                      .setPositiveButton("Ok",
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                      bitMapsAvailable.remove(index - 1);
                    bitMapsFilePath.remove(index - 1);
                    Toast.makeText(MainActivity.this, "Selected video file is deleted successfully.", Toast.LENGTH_SHORT).show();
                    showThumbnails();

                    }
                })

        .setNegativeButton("Cancel",new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
             Toast.makeText(MainActivity.this, "Not deleted", Toast.LENGTH_SHORT).show();

                    }
                });
               AlertDialog dialog=builder.create();
               dialog.show();

                    // if(deleteVideoFile(index-1)){

                }else{
                    Toast.makeText(MainActivity.this, "Not deleted", Toast.LENGTH_SHORT).show();
                }

            }
        };
    }