[英]Call activity from RecyclerView(Xamarin)
I try to call new activity by click event in recycle view. 我尝试通过在回收视图中单击事件来调用新活动。
Here is code, how I do this 这是代码,我该怎么做
This code in Adapter 适配器中的此代码
private Activity _context;
public MovieAdapter(List<Movie> movies,Activity context)
{
this.movies = movies;
_context = context;
}
and here is click event 这是点击事件
void OnItemClick(int position)
{
if (ItemClick != null)
{
_context.StartActivity(typeof(Register));
}
// ItemClick(this, position);
}
In MainActivity I have 在MainActivity中,我有
var moviesAdapter = new MovieAdapter(films.results);
Constructor Movie Adapter has 1 argument 构造函数影片适配器具有1个参数
How I need to write second? 我该如何写第二本书?
Change your code with: 使用以下方法更改代码:
var moviesAdapter = new MovieAdapter(films.results, this);
Here you are passing the instance of the caller which in your case is the MainActivity
class. 在这里,您传递了调用者的实例,在您的情况下是MainActivity
类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.