i have two activity with checkboxs in a list and i have to pass each value of checkbox to another activity and make it checked, where i can't use intent to pass that because both activity is not next together.
In this case how i will store the values in an array and to retrive in another activity
thanks to all, i have done it now and i'm posting it.
int i = 0;
checkBox = new CheckBox[getItemPR.size()];
Constants.INDEX_TEMP_NEW=new int[getItemPR.size()];// stoing in array[]
while (i < getItemPR.size()) {
ITEM dtItem = getItemPR.get(i);
TableLayout table11;
table11 = (TableLayout) LayoutInflater.from(this).inflate(
R.layout.itemoverview2, null);
checkBox[i] = (CheckBox) table11.findViewById(R.id.checkBox1);
checkBox[i].setId(i);
checkBox[i]
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(
CompoundButton buttonView,
boolean isChecked) {
onSetcheckboxchanged(buttonView.getId());
}
});
if (Constants.INDEX_TEMP_NEW[i] == 0) {
checkBox[i].setChecked(true);
} else {
checkBox[i].setChecked(false);
}
and
public void onSetcheckboxchanged(int k) {
if (checkBox[k].isChecked()) {
Constants.INDEX_TEMP_NEW[k] = 0;
} else {
Constants.INDEX_TEMP_NEW[k] = 1;
}
}
Create one java class which will extends to Application class, and get the object of that class by calling App.getInstance() and then you can set or get your selected list item from any activity.
Now register the Application class in Android Manifest.xml under application tag
I usually use a static class/methods for this kind of thing, utilising
SharedPreferences
You can make a singleton class to store the value of the array. eg. 'Storage' class with has the getter, setter of an array. You can set the data here in the class:
In your activity you can access the object of this class using
In this get the data by using getter.