I got a ContentProvider that serves some content e.g. filters.
Those will be rendered in a ListView. Because the filter has many fields I needed to create an own View for the list items. The fields are mapped in a class that extends CursorAdapter.
public void bindView(View view, Context context, Cursor cursor) {
TextView searchPattern = (TextView) view.findViewById(R.id.tv_searchpattern);
TextView searchType = (TextView) view.findViewById(R.id.tv_searchtype);
int type = cursor.getInt(FilterProvider.SEARCH_TYPE_COLUMN);
[...]
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
final View view = inflater.inflate(R.layout.group_list_item, parent, false);
return view;
}
But now I am wondering how I could “carry” the content uris along with the list items.
So that I later can retrieve them later easily to operate (e.g. update, delete) on the item?
Is it a good idea to make use of the View.id field?
view.setId(cursor.getInt(FilterProvider.KEY_COLUMN));
Or am I completely on the wrong track? Do I need to worry because Integer is actually a Long in Sqlite?
errr, I wouldn’t mess with the view IDs like that. Just doesn’t seem like a good idea. I can’t say I have any hard evidence that says so, but the cursor adapter is handling the views, who’s to say some future platform version doesn’t do anything important with the children view IDs?
However, there’s a perfect method for what you want:
http://developer.android.com/reference/android/view/View.html#setTag(java.lang.Object)
So, in your case, you could do :
and then to retrieve it wherever, you would do :
I hope that helps !