I have RecyclerViewAdapter :
public class RecycleViewAdapter extends RecyclerView.Adapter<RecycleViewAdapter.MyViewHolder> {
    private List<Cards> items;
    private int itemLayout;
    Context context;
    public RecycleViewAdapter(List<Cards> items, int itemLayout) {
        this.items = items;
        this.itemLayout= itemLayout;
    }
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
       View view=LayoutInflater.from(parent.getContext()).inflate(itemLayout,parent,false);
        return new MyViewHolder(view);
    }
    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        Cards item=items.get(position);
        holder.title.setText(item.getName());
        String cardvalue = item.getCountry();
        String cardCode = item.getCode();
        String cardCountry = item.getCountry();
    }
    @Override
    public int getItemCount() {
        return items.size();
    }
    public static class  MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
        TextView title;
        public MyViewHolder(View itemView) {
            super(itemView);
            title= (TextView) itemView.findViewById(R.id.listText);
            title.setOnClickListener(this);
        }
        @Override
        public void onClick(View v) {
        }
    }
}
and I need to start new Intent (OnCardsSelected.class)  , but I cant add this line to my method onClick:
Intent intent = new Intent (this, OnCardSelected.class);
I don't understand whats I do wrong, I just need to start Intent and put some information to this intent, I read some manuals but didn't understand theirs explanation so I hope u will help me .Thanks
Probably trying to start Activity from onClick method then use v.getContext() instead of this(which refer to onClick method context) as first parameter to Intent constructor :
Intent intent = new Intent (v.getContext(), OnCardSelected.class);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With