Hello:
I'm having a little bit of trouble with ListView, CursorAdapter, and
a Custom ListItemView. My ListView uses a managedCursor that came
from a content resolver. This cursor is then passed to my class which
we'll call Z that extends the CursorAdapter:
setListAdapter(adpt);
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
In class Z I have the following code:
@Override
public void bindView(View view, Context context, Cursor cursor)
{
//TODO: cache these, perhaps in changeCursor
int nameIndex =
cursor.getColumnIndexOrThrow(Contract.APPINFO_C_S_APPNM);
int pkgIndex =
cursor.getColumnIndexOrThrow(Contract.APPINFO_C_S_PKG);
Holder h = (Holder)view.getTag();
h.desc.setText(cursor.getString(nameIndex));
h.details.setText(cursor.getString(pkgIndex));
h.cb.setChecked(view.isSelected());
// note: cursor adapter saves the row id for us..
}
@Override
/**
* Going with perf best practices and creating a dummy holder
for
the views so they don't have to constantly
* be looked up.
*/
public View newView(Context context, Cursor cursor, ViewGroup
parent) {
final LayoutInflater inflater =
LayoutInflater.from(parent.getContext());
View convertView =
inflater.inflate(R.layout.applistactivity_listitemlayout, null);
final Holder h = new Holder();
h.cb =
(CheckBox)convertView.findViewById(R.id.applistactivity_listitemlayout_selectCB);
h.cb.setTag(h);
h.desc =
(TextView)convertView.findViewById(R.id.applistactivity_listitemlayout_desctv);
h.details =
(TextView)convertView.findViewById(R.id.applistactivity_listitemlayout_detailstv);
convertView.setTag(h);
return convertView;
}
public class Holder {
CheckBox cb = null;
TextView desc = null;
TextView details = null;
long _id = -1;
}
My problem is that I can't figure out how to connect the ListView's
"selected" functionality to the checkboxes in my custom item view so
that they display the state. I've messed around with
addChildrenStates and duplicateParentStates in the XML to no avail.
Thanks in advance and Great Google I/O guys!
--
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