Reputation: 1319
I am facing the issue in viewing the checked checkboxes in android
This is my code
contactNumberList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
CheckBox checkBox = (CheckBox)view.findViewById(R.id.checkbox_number);
AllContact contactNumber = contactsList.get(position);
String num = contactNumber.getNumber();
SelectedSpecificContact specificContact = new SelectedSpecificContact();
specificContact.setNumber(num);
if(!checkBox.isChecked()) {
checkBox.setChecked(true);
realmDbHelper.addSpecificSelectedNumber(specificContact);
Log.e("number", num);
}else{
checkBox.setChecked(false);
specificContact.setNumber(num);
realmDbHelper.deleteAllSelectedData(specificContact);
}
}
});
The list items checked are saved in a database.I want to know which items are checked in a listview. I have initialized the checkbox in listview on item click listener.It shows only the checked checkbox only when the current activity .If the activity is destroyed the checked check boxes are un checked.
How to view the checked check box when the activity appears.
Upvotes: 0
Views: 342
Reputation: 166
Set the checkbox.setChecked(true); with condition where your database returns true condition. Suppose database returns true for the selection on day monday,
if (monday == 1) {
chkMonday.setChecked(true);
Object.setMonday(1);
}
you can do this inside onCreate() or onResume()
Upvotes: 1
Reputation: 3134
Make a boolean or integer field in your bean class is_active
like in SelectedSpecificContact.class
. and set its value to 1
or true
while checked and store in database.
Next time when you load them from database check if it is true
or not.. if true
set the drawable state as checked.
Upvotes: 0