'How in a recycleview started the view by a condition

I have a recycleview which works perfectly I go through an adapter.

on the other hand I would like this view to be displayed not at position 0 but at a position following the name, it is to make a classification by player and I do not see how to do it, searching in the recycleview is not the solution because it does not display the results before and after.

I think it is in the adapter that you have to modify the code attached

Thank you for your help

public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.MyViewHolder> {

private Context mContext;
private List<Product> products = new ArrayList<>();


public RecyclerAdapter (Context context,List<Product> products){
    this.mContext = context;
    this.products = products;
}


public class MyViewHolder extends RecyclerView.ViewHolder {

    private TextView mTitle, mPrice,mPosition;
 /*   private ImageView mImageView;*/
    private RatingBar mRate;
    private LinearLayout mContainer;

    public MyViewHolder (View view){
        super(view);

        mTitle = view.findViewById(R.id.product_title);
  /*      mImageView = view.findViewById(R.id.product_image);*/

        mPrice = view.findViewById(R.id.product_price);
        mContainer = view.findViewById(R.id.product_container);
   mPosition=view.findViewById(R.id.position);


    }
}


@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

    View view = LayoutInflater.from(mContext).inflate(R.layout.products_list_item_layout,parent,false);
    return new MyViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {

    final Product product = products.get(position);

    holder.mPosition.setText(position+1+"");
    holder.mPrice.setText(product.getNom());

    holder.mTitle.setText(product.getPoint());
   /* Glide.with(mContext).load(product.getImage()).into(holder.mImageView);*/



}


Solution 1:[1]

Your question is quite confuse. But... As per my understanding to your question, you have a list and you want to show it in recyclerview by username.

If I am right,

List<String> playerList = Arrays.asList("Ozil", "Odegard", "Son", "Kane", "Neymar");  
List<String> sortedList =playerList.stream().sorted().collect(Collectors.toList());     

//this will sort the list by name order and you can just simply attach it to recycler view

Please tell me if my understanding is wrong.

EDIT

I see. You want to scroll to the specific position. If you can simply get the Username, do like this.

int index = userList.indexOf("user1"); //this will return index of the user1

rv.getLayoutManager().scrollToPosition(index); //this will scroll to user1 position automatically

The above code will scroll to the User1 position. But User1 will not at position 1. I mean you can scroll up if you want. To show User1 at the top of the list, please do the following.

int index = userList.indexOf("user1");

userList.remove(index); // will remove user1
userList.add(0,"user1); //will add user1 add the top

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1