How to show serial number in RecyclerView in android?

I’m making a ranking activity using RecyclerView,

Here is an Image of Ranking Activity.

I want to show serial number (1,2,3…..and so on) in front of each profile picture. How can I do it?

 // Rank View Holder
@Override
protected void onStart() {
    super.onStart();
    Query query = playerDB.orderByChild("score");
    FirebaseRecyclerAdapter<Rank, RankViewHolder>  firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Rank, RankViewHolder>(

            Rank.class,
            R.layout.player_single_rank_layout,
            RankViewHolder.class,
            query
    ) {
        @Override
        protected void populateViewHolder(RankViewHolder viewHolder, Rank model, int position) {

                viewHolder.setName(model.getName());
                viewHolder.setScore(model.getScore());
                viewHolder.setThumbImage(model.getThumbImage(), getApplicationContext());

        }
    };

    playerRankList.setAdapter(firebaseRecyclerAdapter);


}

Answer

I found the solution.

 public static  class RankViewHolder extends RecyclerView.ViewHolder {

    View mView;
    TextView rankPosition;
    public RankViewHolder(View itemView) {
       super(itemView);
       mView = itemView;

        rankPosition = (TextView) mView.findViewById(R.id.rankPosition);

    }


 @Override
 protected void populateViewHolder(RankViewHolder viewHolder, Rank model,int position) {


                viewHolder.setName(model.getName());
                viewHolder.setRuns(model.getRuns());
                viewHolder.setThumbImage(model.getThumbImage(), getApplicationContext());
                // Getting positions here
                viewHolder.rankPosition.setText(String.valueOf(position));
        }

Thanks Ivan for pointing me in the right direction.

Leave a Reply

Your email address will not be published. Required fields are marked *