Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple Checkbox save Android Eclipse
    primarykey
    data
    text
    <p>I managed yet to save my text value and checkbox value trough a save button. Now i want to create 2 (or more) checkboxes, but with current code, it just saves one, not the rest... It must be a small change i have to make, but i can't seem to find it...</p> <pre><code>import android.app.Activity; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.os.Bundle; import android.preference.PreferenceManager; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; public class MainCamperTime extends Activity implements OnClickListener { CheckBox checkBox; EditText editText; Button button; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_camper_time); checkBox = (CheckBox) findViewById(R.id.checkBox1); editText = (EditText) findViewById(R.id.editText1); button = (Button) findViewById(R.id.button1); button.setOnClickListener(this); loadSavedPreferences(); } private void loadSavedPreferences() { SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences(this); boolean checkBoxValue = sharedPreferences.getBoolean("CheckBox_Value", false); String name = sharedPreferences.getString("storedName", "Wanneer vertrekken?"); if (checkBoxValue) { checkBox.setChecked(true); } else { checkBox.setChecked(false); } editText.setText(name); } private void savePreferences(String key, boolean value) { SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences(this); Editor editor = sharedPreferences.edit(); editor.putBoolean(key, value); editor.commit(); } private void savePreferences(String key, String value) { SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences(this); Editor editor = sharedPreferences.edit(); editor.putString(key, value); editor.commit(); } @Override public void onClick(View v) { // TODO Auto-generated method stub savePreferences("CheckBox_Value", checkBox.isChecked()); if (checkBox.isChecked()) savePreferences("storedName", editText.getText().toString()); finish(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload