java - How to reflect changes in preferences to class? -


i created simple class "user" has attribute string username. i'm assuming since android uses java, can create custom classes , it'll use them accordingly. in settingsactivity.java, have:

protected void onpostcreate(bundle savedinstancestate) {     super.onpostcreate(savedinstancestate);     addpreferencesfromresource(r.xml.pref_general);       sharedpreferences sharedpref = getpreferencescreen().getsharedpreferences();     edittextpreference edittextpref = (edittextpreference) findpreference("username");     edittextpref.setsummary(sharedpref.getstring("username", "default"));     //sharedpref.registeronsharedpreferencechangelistener(this);  }  public void onsharedpreferencechanged(sharedpreferences arg0, string arg1) {     // current summary     preference pref = findpreference(arg1);     if(pref instanceof edittextpreference){         edittextpreference etp = (edittextpreference) pref;         pref.setsummary(etp.gettext());         mainmenu.user.setname(etp.gettext()); //this try update class     } } 

as of right now, whenever change value of edittextpreference widget, doesn't update public static user object located in mainmenu. also, followup question - since android saves preferences each instance of app launch, how update user.username string on startup?

in onpostcreate remove comment //

sharedpref.registeronsharedpreferencechangelistener(this); 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -