I believe the issue is that you're getting rowId from
rawContactsCursor (bindView method) which stays on the same record.
IMO you should get row id from cursor coming to you in bindView. This
way you'll get rowId for the record you are currently binding.
To be simple, you are binding to the wrong record.

On Aug 14, 7:50 am, William Ferguson <[email protected]>
wrote:
> I have a ListView that just contains a CheckedTextView.
> I have a very simple CursorAdapter that populates CheckedTextViews.
> When I click on an item, I can see that I am responding to the correct
> row, store the value in my model and the CheckedText gets checked.
>
> However, when I scroll down and then back up again, while I see that
> the model contains the correct value (in #bindView), calling
> #setChecked on the CheckedTextView has no effect. Ie All items are
> unchecked.
>
> Its gotta be something simple, but I can't see it. Any ideas?
>
> public final class SimpleAdapter extends CursorAdapter {
>
>     private static final String TAG = "SimpleAdapter";
>
>     private final LayoutInflater inflater;
>     private final RowModel rowModel = new RowModel();
>
>     public SimpleAdapter(Activity context, MyCursor cursor) {
>         super(context, cursor, true);
>         inflater = (LayoutInflater)
> context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
>     }
>
>     @Override
>     public View newView(Context context, Cursor cursor, ViewGroup
> parent) {
>         final CheckedTextView checkedText = (CheckedTextView)
> inflater.inflate(android.R.layout.simple_list_item_multiple_choice,
> parent, false);
>
>         final MyCursor myCursor = (MyCursor) cursor;
>         checkedText.setText(myCursor.getDescription());
>
>         final Long rowId = rawContactsCursor.getRowId();
>         checkedText.setChecked(rowModel.isSelected(rowId));
>         Log.v(TAG, "rowId=" + rowId + " settingChecked=" +
> rowModel.isSelected(rowId));
>
>         checkedText.setTag(rowId);
>
>         checkedText.setOnClickListener(new View.OnClickListener() {
>             public void onClick(View view) { // Toggle whether the Row
> is selected or not.
>                 final Long id = (Long) view.getTag();
>                 Log.v(TAG, "toggling rowId=" + rowId);
>                 final boolean checked = rowModel.toggleSelected(id);
>                 final CheckedTextView checkedTextView =
> (CheckedTextView) view;
>                 checkedTextView.setChecked(checked);
>             }
>         });
>
>         return checkedText;
>     }
>
>     @Override
>     public void bindView(View view, Context context, Cursor cursor) {
>         final CheckedTextView checkedText = (CheckedTextView) view;
>
>         final MyCursor myCursor = (MyCursor) cursor;
>         checkedText.setText(myCursor.getDescription());
>
>         final Long rowId = rawContactsCursor.getRowId();
>         checkedText.setChecked(rowModel.isSelected(rowId));
>         Log.v(TAG, "rowId=" + rowId + " settingChecked=" +
> rowModel.isSelected(rowId));
>
>         checkedText.setTag(rowId);
>     }
>
> }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to