-3

I wrote a code snippet that change the background color of the LinearLayout by selecting some RadioButtons , the main color of the layout is white , but I want to keep one of these RadioButtons(their color) for always when it is checked , but usually after closing the APP it turns to the main color. how can I use shared preference for this?

My .java file:`

public class Setting extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.setting);

        final LinearLayout ll=(LinearLayout) findViewById(R.id.LinearLayout);
        final RadioButton radio_red = (RadioButton) findViewById(R.id.radio_red);
        final RadioButton radio_yellow = (RadioButton) findViewById(R.id.radio_yellow);

        radio_red.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                ll.setBackgroundColor(Color.RED);
            }
        });

        radio_yellow.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                ll.setBackgroundColor(Color.YELLOW);
            }
        });
    }
}

`

pbaris
  • 4,525
  • 5
  • 37
  • 61
Vahid
  • 1
  • 2
  • Show us how you've tried to use shared preferences so far. The [**documentation**](http://developer.android.com/guide/topics/data/data-storage.html#pref) is very clear on usage. – Overv Oct 05 '14 at 11:52

1 Answers1

0

I have a nice example here:

Android Shared Preferences

You're just going to write a preference and read a preference. Easy Peasy.

Community
  • 1
  • 1
Bill Mote
  • 12,644
  • 7
  • 58
  • 82