I have searched this topic and could not find what I need, so I have to ask for help here. Basically, I have a layout with two fragments. The top fragment shows contact groups and the lower fragment shows all contacts (with group or without). When a user check a group, the app finds all contacts that belong to that group and check or uncheck those contacts in the lower fragment.
When the user check or uncheck the group, I need to update the contact list, not just view (CheckedTextView) but also the data (checked/unchecked). The problem is that getListView().setItemChecked(position, value) only takes position of the list. I have information about the Contact._ID or Contact.DisplayName, but do not know which position of the list to update. I also know the position of the cursor for the item that needs to be updated but that postion value is different from the positon of the list. As a result, when a group is checked/unchecked, always, the wrong contact is checked/unchecked.
I have tried override the bindView() in the customized SimpleCursorAdapter, so that I can toggle the CheckedTextView, but it does not update on the screen.
public void bindView(View view, Context context, Cursor cursor) {
String displayName = cursor.getString(cursor.getColumnIndex(Contacts.DISPLAY_NAME_PRIMARY));
CheckedTextView tv = (CheckedTextView) view.findViewById(android.R.id.text1);
tv.setText(displayName);
if (selectedGroup != null && selectedGroup.containsKey(displayName)) {
tv.setChecked(true);
}
}
I can see that the tx.setChecked(true) gets called, but the affected row on screen is not checked.
Do I need to add a listener to the CheckedTextView? Or do I have to do more after call tv.setChecked?
Thanks a lot.