diff options
author | Android (Google) Code Review <android-gerrit@google.com> | 2009-07-07 16:33:10 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2009-07-07 16:33:10 -0700 |
commit | 028617f246f81eb2fe82df3597cf54c46a2592f1 (patch) | |
tree | c188d6ae85ab11c606c629db52c618f799cffec3 | |
parent | bf847ef45c31772a99c57c655bac828df86eef5c (diff) | |
parent | 36fc94d95d9c03177d45191ec56fb77907ecf13a (diff) | |
download | Calendar-028617f246f81eb2fe82df3597cf54c46a2592f1.tar.gz |
Merge change 6003 into donut
* changes:
b/1926650 Fixed the problem where the checkbox changes in MyCalendars were lost when they scrolled out of view.
-rw-r--r-- | src/com/android/calendar/SelectCalendarsAdapter.java | 32 |
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) { |