gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 00:46:38 25 4
gpt4 key购买 nike

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

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

最佳答案

你可以使用警告对话框

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

}
};
}

关于android - 单击复选框时如何添加确认框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41695770/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com