android - Change a preference through a Dialog -


i want change preference in class if user selects 'ok' in output dialog. have implemented method in class:

if (basalcor != basal) {                      fragmentmanager fragmentmanager = getfragmentmanager();                     changebasaldialog dialogo = new changebasaldialog(basal);                     dialogo.show(fragmentmanager, "tagbasal");                     if (dialogo.check == true) {                         string ok= "basal factor changed succesfully";                         sharedpreferences.editor prefseditor = myprefs.edit();                         if (basalmorframe == true) {                             prefseditor.putstring("basalmor", string.valueof(basal));                             prefseditor.commit();                             toast toast=toast.maketext(mymeasures.this, ok, toast.length_short);                             toast.show();                         }                            if (basalniframe == true) {                             prefseditor.putstring("basalni",                                     string.valueof(basal));                             prefseditor.commit();                             toast toast=toast.maketext(mymeasures.this, ok, toast.length_short);                             toast.show();                         }                     }                     } 

and class changebasaldialog:

    public class changebasaldialog extends dialogfragment{      double basal=0;      boolean check=false;      @override         public dialog oncreatedialog(bundle savedinstancestate) {              alertdialog.builder builder =                     new alertdialog.builder(getactivity());              builder.setmessage("the system recommends new basal factor ("+string.valueof(basal)+"). want set new 1 default?")             .settitle("new basal recommendation avaliable")             .setpositivebutton("yes, want", new dialoginterface.onclicklistener()  {                    public void onclick(dialoginterface dialog, int id) {                             check=true;                             dialog.cancel();                        }                    })             .setnegativebutton("no, i'll keep old value", new dialoginterface.onclicklistener() {                    public void onclick(dialoginterface dialog, int id) {                             dialog.cancel();                        }                    });              return builder.create();         }         public changebasaldialog (double a){      basal=a;      } } 

the problem dialogo.check false if press ok, , cannot change preference ever. want make return dialogo.check=true when press ok button i've tried , don't see it. in advance

when this: dialog.cancel(); reset variables.

i recommend use boolean check outside of changebasaldialog (if have changebasaldialog inside activity).

or implement listener dialogfragment, this documented example.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -