I am very new and would appreciate if someone could demonstrate the code required to save a number of checkbox states in java inside of an android application.
Say i have a list of tools (Ten or more) a user needs to complete a task and would like them to be able to check off each one and have that data saved (within the app, not sQlite) so that it is recorded when they return to the application.
I have some idea of how this is done but really feel like i need to see the code to understand correctly.
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.CheckBox;
public class CheckBoxTest extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.checkboxtest);
CheckBox cb1,cb2,cb3,cb4;
cb1 = (CheckBox)findViewById(R.id.checkBox1);
cb2 = (CheckBox)findViewById(R.id.checkBox2);
cb3 = (CheckBox)findViewById(R.id.checkBox3);
cb4 = (CheckBox)findViewById(R.id.checkBox4);
}
}
Use the below code to store and retrive the data in SharedPreference. Your save each check box state in SharedPreference
//To get value from SharedPreference
//To Save value in SharedPreference
look into it few minor changes::::