How to autoselect 1st item from RecyclerView? Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of How to autoselect 1st item from RecyclerView? without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I have a recyclerView in my app that contain a list of Menu and when i press one of them if will change items in another recyclerView but when i open my activity noone of recyclerView where there are the menu’s are selected.

So the question is how can i open the activity and find the 1st item of the recyclerView selected?

I was trying to simulate an click by Handler but it was making my app slower.

Here is the code from my Adapter :

public class RecyclerViewMenu extends RecyclerView.Adapter<RecyclerViewMenu.MenuViewHolder> {

    private ArrayList<MenuConstructor> menuConstructors;
    private OnItemClickListener onItemClickListener;
    private int selected_position = -1;

    public interface  OnItemClickListener {
        void onItemClick(int position);

    public void setOnItemClickListener(OnItemClickListener listener){
        onItemClickListener = listener;

    public MenuViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.menucard,parent,false);
        return new MenuViewHolder(v, onItemClickListener);


    RecyclerViewMenu(ArrayList<MenuConstructor> menuList){
        menuConstructors = menuList;

    public void onBindViewHolder(@NonNull final MenuViewHolder holder, final int position) {
        MenuConstructor currentItem = menuConstructors.get(position);

        if (selected_position == position) {

        } else {



    public int getItemCount() {
        return menuConstructors.size();

    public class MenuViewHolder extends RecyclerView.ViewHolder {

        public TextView textView;

        MenuViewHolder(View itemView, final OnItemClickListener listener) {

            textView = itemView.findViewById(;

            itemView.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                        if(listener != null){
                            int position = getAdapterPosition();
                            if (position != RecyclerView.NO_POSITION){
                                selected_position = position;




And here is a screenshot of my activity as you can see “CICCIO” is my first item of the recyclerView but it was selected manually.

enter image description here


The variable selected_position should be public in a Utils class and then you set selected_position = 0 in onCreate:

public class Utils {
    public static final int selected_position = -1;

then you use it in onCreate Utils.selected_position = 0; and in onBindViewHolder if (position == Utils.selected_position)

Of course you have to remove this line: private int selected_position = -1;

We are here to answer your question about How to autoselect 1st item from RecyclerView? - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji