Lukazs Pioetrszci
Lukazs Pioetrszci

Reputation: 275

Calling activity method in custom adapter class

So I am currently trying to refresh a recyclerview in another activity but the problem is it doesn't like the casting or the way I am calling it.

Any ideas?

Upvotes: 0

Views: 276

Answers (1)

Francesc
Francesc

Reputation: 29260

From the crashlog, it would appear you are passing an ApplicationContext to your recyclerview. Instead, you need to pass your activity as Context, and ensure your Activity implements the UserRView interface.

A cleaner way would be to pass a context and also pass a UserRView to your adapter, so you do not have to cast the context to UserRView, and you can continue to pass an application context if you prefer.

Edit: replace this code

adapter = new CustomRAdapter(list, getBaseContext());

with

adapter = new CustomRAdapter(list, this);

Upvotes: 1

Related Questions