Skip to content Skip to sidebar Skip to footer

I Want To Implement On Onclicklistener On Cardview And Every Card Takes Me To A Different Activity

I want to replace the toast and I want every card view when clicked takes the user to a new different activity. I would also like to implement Interstitial ads when the user clicks

Solution 1:

You will want to set a click listener on each element in your list.

Inside your onBindViewHolder write something like this:

 holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if(pos == 0){              
               view.getContext().startActivity(new Intent(view.getContext(),Activity1.class));
           }else if(pos == 1){
               view.getContext().startActivity(new Intent(view.getContext(),Activity2.class));
          }
        }
    });
}

Happy Coding ;)


Post a Comment for "I Want To Implement On Onclicklistener On Cardview And Every Card Takes Me To A Different Activity"