[英]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.