I am developing a weather app in which i wanted to use two Views
inside RecyclerView
which is having CursorAdapter
as its member. I want to use one View
to display todays weather and other view to display other days weathers. My RecyclerView
is working perfectly if I only use one View
to display weather. I have also overwritten getItemViewType()? to get to know which
View` type I should inflate.
Code for getItemViewType()
:
private static int VIEW_TYPE_TODAY = 0;
private static int VIEW_TYPE_FUTURE_DAY = 1;
@Override
public int getItemViewType(int position) {
if(position == VIEW_TYPE_TODAY)
return VIEW_TYPE_TODAY;
else
return VIEW_TYPE_FUTURE_DAY;
}
Code for the newView()
of CursorAdapter
which I have overwritten:
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
int viewType = getItemViewType(cursor.getPosition());
int layoutId = -1;
if(viewType==VIEW_TYPE_TODAY)
layoutId = R.layout.list_item_forecast_today;
else if(viewType==VIEW_TYPE_FUTURE_DAY)
layoutId = R.layout.list_item_forecast;
View view = LayoutInflater.from(context).inflate(layoutId, parent, false);
return view;
}
No matter what the value of position
in getItemViewType()
is, the function is always returning VIEW_TYPE_TODAY
.
Can some please tell what I am doing wrong?