Basically here I have three(3) checkbox list in three(3) different fragment. When I open the activity, my checkbox in the default fragment display like normal, but the one in different fragment display differently. The value of the checkbox is still true. Below is the image for the checkbox to make things clearer and also my code.
First fragment page:
Second fragment page:
Code for setting up the checkbox and its if condition
private void setCheckBox(ArrayList<DataPrefType> arrayList){
for(int i = 0; i < arrayList.size(); i++){
id = i + 1;
checkBox = new CheckBox(getActivity());
checkBox.setId(i + 1);
checkBox.setText(arrayList.get(i).getName());
checkBox.setPadding(10, 10, 10, 10);
checkBox.setLayoutParams(params);
checkBox.setGravity(Gravity.CENTER);
checkBoxLayout.addView(checkBox);
if(!userPreference.isEmpty() || userPreference != null){
for(int j = 0; j < userPreference.get(0).getDataPrefTypeArrayList().size(); j++){
int retrieveId = Integer.parseInt(userPreference.get(0).getDataPrefTypeArrayList().get(j).getId());
if(checkBox.getId() == retrieveId)
checkBox.setChecked(true);
}
}
Aucun commentaire:
Enregistrer un commentaire