简体   繁体   中英

How to send data From One RecyclerView Item to load another RecyclerView using Nested JSON

I am developing a Cinema App, but I want to use 2 RecyclerViews, one has successfully loaded, it contains the list of cinemas, then I want when someone taps on any of the Cinemas it loads another list of RecyclerView containing Movies.

How can I deal with 2 RecyclerViews?

Am new in Android. Below is the link to the sample of codes:

This is the link of the sample codes

RecyclerView Item to Load Another RecyclerView with Nested JSON

You have to options here:

  1. The two recycler views are displayed on the screen at the same time.

This will imply the data in the 2nd recylcler view need the ability to change multiple times.

Add this code in your onItemSelectListener from your cinemaRecyclerView

Cinema selectedCinema = cinemas.get(selectedPosition); // This is the selected cinema from the CinemaRecyclerView;
moviesAdapter.updateMovies(selectedCinema.getMovies);

In your MovieAdapter class add the following method.

public void updateMovies(List<Movie> movies){
    this.movies.clear();
    this.movies.addAll(movies);
    notifyDataSetChanged();
}
  1. The cinema recycler view is on one screen and the movies list is on the next screen.

Here you will need to pass the selected Cinema object to the next Activity/Fragment. Based on this selection you can directly instantiate your MoviesAdapter with the correct movies list.

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