Update a Switch from a Dialog

0

I have a Dialog like this:

public void Dialogo_Iluminacao() {


    final Dialog dialog = new Dialog(this);

    dialog.setContentView(R.layout.dialogo_iluminacao);

    dialog.setTitle("Iluminação");

    final Switch garagem = (Switch) dialog.findViewById(R.id.switchGaragem);
    final Switch jardim = (Switch) dialog.findViewById(R.id.switchJardim);
    final Switch sala = (Switch) dialog.findViewById(R.id.switchSala);


    garagem.setChecked(luzgaragem);
    jardim.setChecked(luzjardim);
    sala.setChecked(luzsala);
    holofote.setChecked(luzholofote);
    fundo.setChecked(luzfundo);
    lateral.setChecked(luzlateral);

    garagem.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        doCommand((garagem.isChecked() ? "acenda" : "apague") + " garagem", false);
                        garagem.setChecked(luzgaragem);
        }
    });

    jardim.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            doCommand((jardim.isChecked() ? "acenda" : "apague") + " jardim", false);
        }
    });

    sala.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            doCommand((sala.isChecked() ? "acenda" : "apague") + " sala", false);
        }
    });
 dialog.show();
}

When I click on the switch garage, garden or room it calls a function that if it works return a boolean. Problem I can only change the state of the on / off switch after I have this return how should I do this?

I need to change the Switch state when I have a return on this function

public void OnStatusDaLuzRecebido(final Boolean b, final String setor) {

    new Thread() {
        public void run() {
            try {
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {


                        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
                        DateFormat horaformat = new SimpleDateFormat("HH:mm:ss");
                        Date date = new Date();
                        String dataagora = dateFormat.format(date);
                        switch (setor) {
                            case "garagem":
                                luzgaragem = b;
                                Toast.makeText(getApplicationContext(), (b ? " acesa " : "apagada"), Toast.LENGTH_LONG).show();
                                break;
                            case "jardim":
                                luzjardim = b;
                                Toast.makeText(getApplicationContext(), "Jardim " + (b ? "aceso" : "apagado"),
                                                Toast.LENGTH_LONG).show();
                                break;
                            case "sala":
                                luzsala = b;
                                Toast.makeText(getApplicationContext(), "Luz " + (b ? "acesa" : "apagada"), Toast.LENGTH_LONG).show();
                                break;
    });
                Thread.sleep(300);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }.start();

}
    
asked by anonymous 24.02.2015 / 14:11

0 answers