Add serial number to recyclerview
I am trying to add serial number to a textview in android recyclerview. But it throws the below error
My code is here
@Override
public void onBindViewHolder(final RViewHolder holder,final int position) {
final commdtylist listitem=listitems2.get(position);
for(i=1;i<=listitems2.size();i++){
holder.comm_code.setText(i);
}
Instead of
@Override
public void onBindViewHolder(final RViewHolder holder,final int position) {
final commdtylist listitem=listitems2.get(position);
for(i=1;i<=listitems2.size();i++){
holder.comm_code.setText(i);
}
}
Use
@Override
public void onBindViewHolder(final RViewHolder holder,final int position) {
final commdtylist listitem=listitems2.get(position);
holder.comm_code.setText(String.valueOf(position+1));
}
Use this
holder.comm_code.setText(String.valueOf(position+1));