this may be a stupid question as I am new to this, but is there anyway to create a class which stores not the sharedpreferences of a user but the result of shared preferences? As I have a main screen which will be generating possibly hundreds of dynamic ImageButtons(Obviously no more then half a dozen or so at a time) based on the users input.
So far I am putting this in my main screen code, which works fine but it just does not seem feasable/possible to do it for all the different possible inputs.
ImageButton ab = new ImageButton(this);
ImageButton ca = new ImageButton(this);
ca.setId(R.id.ca);
ab.setId(R.id.ab);
SharedPreferences caprefs = PreferenceManager.getDefaultSharedPreferences(this);{
LinearLayout ll = (LinearLayout)findViewById(R.id.sundayboxopen
);
if(caprefs.getBoolean("cacheckBoxon", true)) {
ll.addView(ca);
ca.setImageResource(R.drawable.cobutton1);
ca.setBackgroundColor(View.GONE);
}else{
if(caprefs.getBoolean("cacheckBoxoff", true)){
ll.addView(ca);
ca.setVisibility(View.GONE);}
}}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);{
LinearLayout ll = (LinearLayout)findViewById(R.id.sundayboxopen);
if(prefs.getBoolean("checkBoxon", true)) {
ll.addView(ab);
ab.setImageResource(R.drawable.adaba);
ab.setBackgroundColor(View.GONE);
}else{
if(prefs.getBoolean("checkBoxoff", true)){
ll.addView(ab);
ab.setVisibility(View.GONE);}
}}
As you can see there are just two buttons there ca
and ab
, It would be great if I could store these processes separatley across one or a few dedicated class' which were checked 'behind the curtains' when I start/restart the app. Thanks in advance