i am trying to set cursor adapter with two different layouts, first one must be unique, others - the same, but getItemViewType(cursor.getPosition());
always return 0...
here is my adapter:
public class MyAdapter extends CursorAdapter
public static class ViewHolder {
public ViewHolder (View rootView){}}
public ProfileAdapter(Activity activity, Cursor c) {
super(activity, c);
mActivity = activity;
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
int mLayoutId = -1;
mViewType = getItemViewType(cursor.getPosition());
if (mViewType == VIEW_TYPE_MAIN){
mLayoutId = R.layout.main;
} else {
mLayoutId = R.layout.list_items;
}
View rootView = LayoutInflater.from(context).inflate(mLayoutId, parent, false);
ViewHolder viewHolder = new ViewHolder(rootView);
rootView.setTag(viewHolder);
return rootView;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
mCursor = cursor;
mView = view;
mViewHolder = (ViewHolder) view.getTag();
mViewType = getItemViewType(cursor.getPosition());
if (mViewType == VIEW_TYPE_MAIN){
} else {
}
}
feeling like I am missing something very simple... Will be glad any ideas how to solve this staff!
Your adapter must implement getViewTypeCount()
(and return 2 in your case) and also implement getItemViewType()
. Default implementation got no idea about your data and won't try to figure this out. It will just handle the case where there is only one view type used (hence the 0 returned). Add missing methods and you should be good.