title: How to setOnClickListener in adapter using RecyclerView to display inside fragment
body: <p>I cannot access the ID of the item to view it in ToastMessage, or even store it in the database (use Room DataBase)
  I have tried but the message does not appear
  I need the reference ID to use for database storage and complete the process for storing the shopping cart</p>
  <p>itemAdapter.java</p>
  <pre><code>public class itemAdapter extends RecyclerView.Adapter&lt;itemAdapter.ItemViewHolder&gt; {
      private Context context;
      private ArrayList&lt;Items&gt; arrayList;
      private AdapterView.OnItemClickListener listener;
      public itemAdapter(Context context, ArrayList&lt;Items&gt; arrayList) {
          this.context = context;
          this.arrayList = arrayList;
      }
  
      @NonNull
      @Override
      public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
          View v = LayoutInflater.from(context).inflate(R.layout.item, parent, false);
          return new ItemViewHolder(v);
      }
  
  
      @Override
      public void onBindViewHolder(@NonNull ItemViewHolder holder, int position) {
          holder.name.setText(arrayList.get(position).getItemName());
          holder.desc.setText(arrayList.get(position).getItemDesc());
          holder.price.setText(arrayList.get(position).getItemPrice());
          holder.add.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Toast.makeText(context,arrayList.get(position).getItemIid(),Toast.LENGTH_SHORT);
              }
          });
          holder.name.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Toast.makeText(context,arrayList.get(position).getItemPrice(),Toast.LENGTH_SHORT);
              }
          });
  
      }
  
      @Override
      public int getItemCount() {
          return arrayList.size();
      }
  
      class ItemViewHolder extends RecyclerView.ViewHolder {
  
          TextView name, desc, price;
          ImageView remove, add;
  
          public ItemViewHolder(@NonNull View itemView) {
              super(itemView);
              name = itemView.findViewById(R.id.tvName);
              desc = itemView.findViewById(R.id.tvDesc);
              price = itemView.findViewById(R.id.tvPrice);
              remove = itemView.findViewById(R.id.btnDelete);
              add = itemView.findViewById(R.id.btnAdd);
          }
      }
     
  }
  </code></pre>
  <p>MealsFragment.java</p>
  <p>public class MealsFragment extends Fragment {</p>
  <pre><code>public MealsFragment() {
      // Required empty public constructor
  }
  
  RecyclerView recyclerView;
  itemAdapter adapter;
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
  
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      return inflater.inflate(R.layout.fragment_meals, container, false);
  }
  
  @Override
  public void onViewCreated( View view, Bundle savedInstanceState) {
      ArrayList&lt;Items&gt; ItemsList = (ArrayList&lt;Items&gt;) RoomDatabaseSingleton.getInstance(getContext().getApplicationContext())
              .getAppDatabase()
              .getDao()
              .getItems(&quot;meals&quot;);
      recyclerView = view.findViewById(R.id.rvMeals);
      RecyclerView.LayoutManager manager = new LinearLayoutManager(
              getContext(), RecyclerView.VERTICAL, false);
      recyclerView.setLayoutManager(manager);
      adapter = new itemAdapter(getContext(), ItemsList);
      recyclerView.setAdapter(adapter);
  
  }
  </code></pre>
  <p>}</p>