android - changing ListPreference value from an Activity -


following new api's have created pretty simple preferencefragment:

  public class prefsfragment extends preferencefragment {  @override public void oncreate(bundle savedinstancestate) {      super.oncreate(savedinstancestate);      addpreferencesfromresource(r.xml.preferences); }      } 

i use in activity created enable user change app settings:

  public class setpreferenceactivity extends activity {  @override protected void oncreate(bundle savedinstancestate) {      super.oncreate(savedinstancestate);      getfragmentmanager().begintransaction()             .replace(android.r.id.content, new prefsfragment()).commit();  }     } 

now need change summary of listpreference according user's choice. there no findpreference() method defined activity class, so how can access desired preference?

sorry if answer obvious, i'm not familiar new api , used preferenceactivity before became deprecated..

instead of doing new prefsfragment() right in statement replace fragment can this.

preferencefragment pfrag = new prefsfragment(); prefsfragment pf = (prefsfragment)pfrag;  getfragmentmanager().begintransaction()         .replace(android.r.id.content, pfrag).commit(); 

then in preferencefragment create public method can change want

pf.changemypreference(); 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -