Search code examples
androidonclicklistener

How to move a different activity on recycler view click?


I want to move to different activity when I click any of the recycler view. But when I'm clicking on any of them it is going to the same activity

ArrayList<FeaturedHelperClass> featuredLocations = new ArrayList<>();

featuredLocations.add(new FeaturedHelperClass(R.drawable.auditorium_a, "Mahatma Gandhi Auditorium", "It is a long established fact that a reader."));
featuredLocations.add(new FeaturedHelperClass(R.drawable.auditorium_a, "Nethaji Auditorium", "It is a long established fact that a reader."));
featuredLocations.add(new FeaturedHelperClass(R.drawable.auditorium_a, "V.O.C. Auditorium", "It is a long established fact that a reader."));
featuredLocations.add(new FeaturedHelperClass(R.drawable.audtiorium_b, "Conference Room - AB", "It is a long established fact that a reader."));
featuredLocations.add(new FeaturedHelperClass(R.drawable.audtiorium_b, "RUBY (Admin Block)", "It is a long established fact that a reader."));
featuredLocations.add(new FeaturedHelperClass(R.drawable.smart_classroom, "Smart Class", "It is a long established fact that a reader."));

adapter = new FeaturedAdapter(featuredLocations, this);
featuredRecycler.setAdapter(adapter);

Solution

  • Go to adapter class at under onBindViewHolder create holder.view.setOnClickListener

    For example:

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        
    
        holder.itemView.setOnClickListener(view -> {
    
                    Intent reminderActivity = new Intent(view.getContext(), CoinReminderActivity.class);
                    reminderActivity.putExtra(Constants.COIN_NAME, currencies.getCoinName().toLowerCase());
                    view.getContext().startActivity(reminderActivity);
    
        });