Reputation: 2613
I have two different layouts.The app is starting with the first one but i would like the user to change it two my second layout,if he prefer it.How can i do it?Thanks
Upvotes: 0
Views: 180
Reputation: 3021
Just keep a value in SharedPreferences.Let,it is userSelected.If user select that layout then put userSelected as true in SharedPreferences.
Now,before setContentView or Layout inflayout check the value of SharedPreferences.If its true then use(set as setContentView or layoutInFlayout) 2nd layout otherwise use default one.
Did you get my point?
if (userSelected == true){
setContentView(R.layout.a)
} else{
setContentView(R.layout.b)
}
Upvotes: 0
Reputation: 3005
Use this instead, just pull pref from your SharedPreferences
if (pref == 1){
setContentView(layout1)
} else{
setContentView(layout2)
}
Or you could make it a boolean as mentioned
Upvotes: 1
Reputation: 26557
There are several ways, the easier is probably to create a boolean preference (or an integer if you want to handle more than two layouts), and if it is set to true, then you load a specific layout and if not you load the other one :
if (prefs.getBoolean("firstLayout", true))
setContentView(R.layout.first);
else
setContentView(R.layout.second);
Upvotes: 0