简体   繁体   English

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

[英]How to add confirm box when i click on checkbox?

I have two dynamic check box one is for deleting video and another is for saving video.I want to add a confirm box so that it confirms my action when i click on checkbox.How to add the confirm box in my code?我有两个动态复选框,一个用于删除视频,另一个用于保存视频。我想添加一个确认框,以便在我单击复选框时确认我的操作。如何在我的代码中添加确认框?

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();
            }
        }
    };
    }

You can use alert dialog您可以使用警报对话框

    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();
                }

            }
        };
    }

Just user alertdialog for it:只是用户警报对话框:

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();

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 单击和取消单击时如何更改复选框颜色? - How can I change Checkbox color when I click and unclick? 我想要在单击checkbox1时,然后检查它,如果checkbox2在之前被选中,则将其强制为未选中状态(对于android) - I want when click on check box1, then it chekecd and if checkbox2 is checked before , force it to no checked state(for android) 如何添加显示我单击的图像和橡皮擦的框 - How do I can add a box show the image I click and eraser 如何在 Rubymotion webview 中添加确认 AlertDialog? - How do I add a confirm AlertDialog in a Rubymotion webview? 如何根据json数组长度在对话框中添加动态复选框? - How to add dynamic checkbox in dialog box according to json array length? 单击按钮时如何添加不同的图层 - how to add different layer when i click a button 单击图像时如何向图像添加简单的效果或动作? - How can I add a simple effects or action to the image when click on it? 单击微调框时如何在编辑文本中添加项目? - how to add items in edit text when i click on spinner? 如何在kotlin中设置确认删除AlertDialogue框 - How to Set confirm delete AlertDialogue box in kotlin 如何获得Cordova navigator.notification.confirm对话框来触发inappbrowser? - How can I get the Cordova navigator.notification.confirm dialog box to trigger inappbrowser?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM