i want to add header to recycle view i am trying to achieve it using
@Override
public int getItemViewType(int position) {
// depends on your problem
if (position == 0 || position == 4) {
return 2;
} else {
return 1;
}
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
// create a new view
if (viewType == 1) {
View itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(
R.layout.cardview_row, null);
return new ViewHolder(itemLayoutView);
} else if (viewType == 2) {
View itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(
R.layout.cardview_row1, null);
return new ViewHolders(itemLayoutView);
}
return null;
}
but how i can do it in run time like when i don't know position when it should show section like i have json
{
"DATA": [
"hi",
"heloo",
"bye"
],
"MAHA": [
"ans",
"rs",
"re",
"jab",
"bad"
]
}
where data and maha is section i want to display other elements
currently i am making arraylist of all elements and adding hardcore value for section but how i can do this viva using above json