android - How to show specific properties in the settings -


in android application have setting layout 4 properties. can call settings mainactivity , noticeactivity. have overwritten method:

 @override  public boolean onoptionsitemselected(menuitem item) {     switch (item.getitemid()) {          case r.id.action_settings:             intent intent = new intent(this, settingsactivity.class);             startactivity(intent);             return true;     }  } 

to show settings have these 2 classes:

public class settingsactivity extends preferenceactivity implements sharedpreferences.onsharedpreferencechangelistener {    @override    protected void oncreate(bundle savedinstancestate) {        super.oncreate(savedinstancestate);         getfragmentmanager().begintransaction()             .replace(android.r.id.content, new settingsfragment())             .commit();    } }  public class settingsfragment extends preferencefragment {    @override    public void oncreate(bundle savedinstancestate) {        super.oncreate(savedinstancestate);         // preference_general -> layout 4 properties        addpreferencesfromresource(r.xml.preference_general);    } } 

what want is: if settings called mainactivity, want show 4 properties, if called noticeactivity want show first three.

how can without creating second layout?

you can defining constant in intent in both activity.for example:

intent intent = new intent(this, settingsactivity.class); intent.putextra("activity","first_activity"); startactivity(intent); 

remember, name "activity" should same in both activities. , use checking calling specific settings in setting activity. example:

public class settingsactivity extends preferenceactivity implements sharedpreferences.onsharedpreferencechangelistener { @override protected void oncreate(bundle savedinstancestate) {    super.oncreate(savedinstancestate);     intent = getintent();    string checkingvalue = i.getstringextra("activity");     if(checkingvalue != null){   //or else        //setting layout 4 properties    }else{       //setting layout 3 properties    } } } 

hope help!


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -