I try to remember the checkbox within a dialogue but in comparison remember == false the variable remember still has not changed its value. In the loop is iterated as many times as the size of lelements_tmp before call showDialogSameFile() so neither can I use the variable remember within the loop. How can I do it? Thanks in advance.
private boolean remember = false;
// in the program
// add files to List lelements_tmp
while (i < lelements_tmp.size()) {
File fto = new File(lelements_tmp.get(i).getFile());
String to = null;
try {
to = fto.getCanonicalPath();
} catch (IOException e) {
e.printStackTrace();
}
if (fto.exists()) {
showDialogSameFile(fto, to, i);
i++;
continue;
}
thread(i);
i++;
}
private void showDialogSameFile(File f, String to, final int i) {
TextView title = null;
if (f.isDirectory())
title = this.getTitle("The directory " + to + " already exists. Do you want to replace the contents?");
else if (f.isFile())
title = this.getTitle("The file " + to + " already exists. Do you want to replace it?");
String[] item = {"Apply to all"};
AlertDialog ad = new AlertDialog.Builder(context)
.setCustomTitle(title)
.setMultiChoiceItems(item, null,
new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked) {
if (isChecked)
remember = true;
}
})
.setPositiveButton("Aceptar",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
thread(i);
}
})
.setNegativeButton("Cancelar",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.create();
if (remember == false)
ad.show();
}