summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Chan <mchan@android.com>2009-07-01 18:18:54 -0700
committerMichael Chan <mchan@android.com>2009-07-01 18:18:54 -0700
commit36fc94d95d9c03177d45191ec56fb77907ecf13a (patch)
tree95ee38b7e2e7ff99cfe7432a746e3a9710922237
parent3730311bfec28a07040dc3caf261fb5d2585b43b (diff)
downloadCalendar-36fc94d95d9c03177d45191ec56fb77907ecf13a.tar.gz
b/1926650 Fixed the problem where the checkbox changes in MyCalendars were lost when they scrolled out of view.
modified: src/com/android/calendar/SelectCalendarsAdapter.java
-rw-r--r--src/com/android/calendar/SelectCalendarsAdapter.java32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/com/android/calendar/SelectCalendarsAdapter.java b/src/com/android/calendar/SelectCalendarsAdapter.java
index fb50662a..a3eab03e 100644
--- a/src/com/android/calendar/SelectCalendarsAdapter.java
+++ b/src/com/android/calendar/SelectCalendarsAdapter.java
@@ -49,11 +49,16 @@ public class SelectCalendarsAdapter extends CursorAdapter {
private final LayoutInflater mInflater;
private final ContentResolver mResolver;
private final ContentValues mValues = new ContentValues();
+ private Boolean mIsChecked[] = null;
+ private static final Boolean CHECKED = true;
+ private static final Boolean UNCHECKED = false;
private class CheckBoxListener implements CheckBox.OnCheckedChangeListener {
private final long mCalendarId;
+ private final int mPosition;
- private CheckBoxListener(long calendarId) {
+ private CheckBoxListener(long calendarId, int position) {
+ mPosition = position;
mCalendarId = calendarId;
}
@@ -63,13 +68,19 @@ public class SelectCalendarsAdapter extends CursorAdapter {
int checked = isChecked ? 1 : 0;
mValues.put(Calendars.SELECTED, checked);
mResolver.update(uri, mValues, null, null);
+ mIsChecked[mPosition] = isChecked ? CHECKED : UNCHECKED;
}
}
+ private void updateIsCheckedArray(int cursorCount) {
+ mIsChecked = new Boolean[cursorCount];
+ }
+
public SelectCalendarsAdapter(Context context, Cursor cursor) {
super(context, cursor);
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mResolver = context.getContentResolver();
+ updateIsCheckedArray(cursor.getCount());
}
@Override
@@ -87,10 +98,25 @@ public class SelectCalendarsAdapter extends CursorAdapter {
setText(view, R.id.calendar, cursor.getString(nameColumn));
CheckBox box = (CheckBox) view.findViewById(R.id.checkbox);
long id = cursor.getLong(idColumn);
- boolean checked = cursor.getInt(selectedColumn) != 0;
+
+ // Update mIsChecked array is needed
+ int cursorCount = cursor.getCount();
+ if (cursorCount != mIsChecked.length) {
+ updateIsCheckedArray(cursorCount);
+ }
+
+ // If the value hasn't changed, read from cursor; otherwise, read from mIsChecked array.
+ boolean checked;
+ int position = cursor.getPosition();
+ if (mIsChecked[position] == null) {
+ checked = cursor.getInt(selectedColumn) != 0;
+ } else {
+ checked = (mIsChecked[position] == CHECKED);
+ }
+
box.setOnCheckedChangeListener(null);
box.setChecked(checked);
- box.setOnCheckedChangeListener(new CheckBoxListener(id));
+ box.setOnCheckedChangeListener(new CheckBoxListener(id, position));
}
private static void setText(View view, int id, String text) {