I want to add advertisement View after RecyclerView 1,2,3 position and then advertisement View and then RecyclerView 4,5,6 position and then advertisement View and then 7,8,9,10,11... How to handle position to add extra 3 RecyclerView?
Asked
Active
Viewed 427 times
0
-
2You dont want to do that. You want to use another ViewHolder for ads – Vygintas B Jan 30 '17 at 11:13
-
[How to create RecyclerView with multiple view type?](http://stackoverflow.com/questions/26245139/how-to-create-recyclerview-with-multiple-view-type) – Vygintas B Jan 30 '17 at 11:14
2 Answers
0
No no.. don't nest your recyclerview.. use multiple ViewHolder with different layout..
Override getItemViewType with your desired config
@Override
public int getItemViewType(int position) {
return items.get(position).getType();
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = null;
switch (viewType) {
case ITEM:
view = mInflater.inflate(R.layout.your_row_a, parent, false);
return new ATypeViewHolder(view);
case HEADER:
view = mInflater.inflate(R.layout.your_row_b, parent, false);
return new BTypeViewHolder(view);
}
}

ZeroOne
- 8,996
- 4
- 27
- 45
0
use Fuction Like That To see If position After 3 Or Not and I realy Dont Sure CurrentP % 3 != 0 OR CurrentP % 3 != 1
private IsAfrerTree(int position)
{
int CurrentP = position+1;
if(CurrentP % 3 != 0)
{
return true;
}
else
{
return False;
}
}

Elsunhoty
- 1,609
- 14
- 27