I have a void method that creates a custom dialog that shows a listview multichoice, I would like this method to return a boolean when the positivebutton or negativebutton is clicked to do another operation on the method that calls it.
Void method
public void listaRecorrente(final List<Receita> list) {
AlertDialog.Builder ab = new AlertDialog.Builder(this);
ab.setTitle("Parcelas");
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.list_dialog, null);
final ListView lv = (ListView) view.findViewById(R.id.list_dlg);
final Button tudo, nada;
tudo = (Button) view.findViewById(R.id.btTodas);
nada = (Button) view.findViewById(R.id.btNenhuma);
tudo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
for (int o = 0; o < lv.getAdapter().getCount(); o++)
lv.setItemChecked(o, true);
}
});
nada.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
for (int o = 0; o < lv.getAdapter().getCount(); o++)
lv.setItemChecked(o, false);
}
});
lv.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
lv.setDivider(null);
final ReceitaDAO dao = new ReceitaDAO(this);
ArrayAdapter<Receita> aa = new ArrayAdapter<>(this, android.R.layout.select_dialog_multichoice, list);
lv.setAdapter(aa);
ab.setView(view);
ab.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
final Handler mHandler = new Handler();
progress.show();
Thread t = new Thread(new Runnable() {
@Override
public void run() {
int len = lv.getCount();
SparseBooleanArray checked = lv.getCheckedItemPositions();
for (int y = 0; y < len; y++) {
if (checked.get(y)) {
dao.deletarRecorrente(list.get(y).getId());
dao.deletar(list.get(y));
}
}
mHandler.post(new Runnable() {
@Override
public void run() {
progress.hide();
}
});
}
});
t.start();
chamaToast("Receitas excluídas!");
}
});
ab.setNegativeButton("CANCELAR", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
ab.show();
}