Update activity from Alertdialog

Asked

Viewed 48 times

1

Every time I click on Toolbar I have a menu that when clicking on one of the options I see a AlertDialog. This Alertdialog has a setSingleChoiceItems, where the user choosing an option and clicking OK, this option is saved in the BD. All this works well. The problem is that when returning to the activity I want to q appear different information depending on the choice that the user made in Alertdialog and I am not able to.

I’m using the Onresume()

    mes = (TextView) findViewById(R.id.textMes);
    metaDef = (TextView) findViewById(R.id.textMetaDef);
    despesa = (TextView) findViewById(R.id.textDesp);

    if (db_helper.hasMoeda()) {
        moeda = db_helper.getMoeda();
    } else {
        db_helper.updateMoeda("Euro");
    }

    Gasto gasto=new Gasto();
    gasto=db_helper.getGasto();

    mes.setText(gasto.getMes());

    if (moeda.equalsIgnoreCase("Euro")) {
        metaDef.setText("" + gasto.getMeta() + " €");
        despesa.setText(String.format("%.2f €", gasto.getDespesa_final()));
    } else if (moeda.equalsIgnoreCase("Real")) {
        metaDef.setText("R$ " + gasto.getMeta());
        despesa.setText(String.format("R$ %.2f", gasto.getDespesa_final()));

    }

What is happening is that the activity is not updated when I click on the OK of the alertDialog. Does anyone have any suggestions?

  • Is a Alertdialog or a Dialogfragment?

  • @ramaral , Alertdialog..... Alertdialog.Builder Builder=new Alertdialog.Builder(this);

  • Then you should update the information from Activity in the method onClick() button OK of Alertdialog and not in the onResume()

  • @ramaral, my Alertdialog is in another class, in that class I have an onClick but it is to validate the option that user chooses. The problem is that when I left Alertdialog I wanted to be made a kind of refresh in the activity...then use onResume()

  • In what other class? Other Activity or a class inherited from Alertdialog. Please rephrase the question in order to have all the information.

  • the information chosen in the dialod should reflect in Activity... is it? choose in the dialog and change something in Activity when closing the dialog... that’s it?

  • @Flipnovid when clicking the Alertdialog Ok when I return the activity should show a certain information that does not show...(in Alertdialog the user chooses the currency...when he returns to the Activity he should execute the part of the if code (currency.equalsIgnoreCase("Euro").... and does not perform)

  • 1

    You should call back in your dialog.. Has Jah done this before? Want me to post it here? so on the return of your dialog or on your click changes the value in Activity

  • when the dialog is closed Activity or Fragment is not entering your onResume...this is clear

  • @Flipnovid thank you, I will investigate! :)

  • @porthfind managed to solve?

  • @Flipnovid I will see this fds

  • @porthfind ok... anything calls here... that I put an example... put if succeeded

  • @Flipnovid can for example pf? I can’t solve my problem :\

Show 9 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.