简体   繁体   中英

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

 var moviesAdapter = new MovieAdapter(films.results);

Constructor Movie Adapter has 1 argument

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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