0
I have a void method that creates a custom dialog that shows a listview Multichoice, I would like to make this method return a Boolean when positivebutton or negativebutton is clicked to do another operation in 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();        
}
						
I couldn’t figure out which method you want to return the Boolean? The operations you must do after a positivebutton or negativeButton button is pressed must be implemented within the onClick button.
– Skywalker