所以,我在 RecyclerView 中启动一个项目的“YouTube 播放器”onClick
。但是,这里我有一个问题:
Intent intent = YouTubeStandalonePlayer.createVideoIntent(itemView.getContext(), DeveloperKey.DEVELOPER_KEY, "cdgQpa1pUUE");
itemView.getContext().startActivity(intent);
itemView
是 View ,在这里
createVideoIntent(itemView.getContext()
Android 工作室说:
Wrong 1st Argument type found,'Android.content.Context', Required 'android.app.Activity'
我该如何解决?我尝试了类似的问题,但这些问题的解决方案仅限于 Fragments 和支持库,例如 v4 和 v7。非常感谢任何帮助,谢谢!
最佳答案
试试这个,
Activity activity = (Activity) itemView.getContext();
Intent intent = YouTubeStandalonePlayer
.createVideoIntent(activity, DeveloperKey.DEVELOPER_KEY, "cdgQpa1pUUE");
itemView.getContext().startActivity(intent);
关于android - 在 RecyclerView 的适配器中获取上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35464232/