mercredi 27 mai 2015

Start Activity from RecycleView Adapter on click

I have an issue starting a new activity from a CardView Adapter, this is the code:

RVAdapter adapter = new RVAdapter(array_restaurants);
recList.setAdapter(adapter);

And after in the adapter. I set an OnClickListener

personName.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                Context context = v.getContext();
                System.out.println("Context");
                System.out.println(context.toString());
                Intent intent = new Intent(v.getContext(), Restaurante.class);
                v.getContext().startActivity(intent);
            }
        });

When i print the context in the console everything looks fine, but after the aplication stop working. Why?

Thank you very much.

Aucun commentaire:

Enregistrer un commentaire