0

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

ToeKnee
  • 47
  • 1
  • 10
  • Are you planning to store image buttons in shared preferences? – Szymon Nov 10 '13 at 09:44
  • Well if I can and draw on them dynamically but i'll still have to have all the code for everyone of them on the page they're to appear in right? – ToeKnee Nov 10 '13 at 10:40
  • Yes, you should store information that will allow you to re-create them. – Szymon Nov 10 '13 at 10:58
  • How would I go about that?, I only seem to be able to store and retrieve shared Checkbox' and boolean values. Is there a tutorial or link you can give me? – ToeKnee Nov 10 '13 at 12:09
  • Like that one: http://www.vogella.com/articles/AndroidFileBasedPersistence/article.html#preferences_overview. Shared preferences have methods to store each primitive type so you will be able to store enough to reconstruct buttons. – Szymon Nov 10 '13 at 19:30

0 Answers0