简体   繁体   English

定制适配器类中的调用活动方法

[英]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. 因此,我目前正在尝试在另一项activity刷新recyclerview ,但问题是它不喜欢casting或我所说的方式。

Any ideas? 有任何想法吗?

From the crashlog, it would appear you are passing an ApplicationContext to your recyclerview. 从崩溃日志中,您似乎正在将ApplicationContext传递到recyclerview。 Instead, you need to pass your activity as Context, and ensure your Activity implements the UserRView interface. 相反,您需要将活动作为上下文传递,并确保您的活动实现了UserRView接口。

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. 较干净的方法是传递上下文,还将UserRView传递给适配器,因此您不必将上下文强制转换为UserRView,并且可以根据需要继续传递应用程序上下文。

Edit: replace this code 编辑:替换此代码

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

with

adapter = new CustomRAdapter(list, this);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM