Skip to content

Instantly share code, notes, and snippets.

@Velmm
Created December 28, 2017 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Velmm/92ec3986f0f0f02018c1ef2358ea8317 to your computer and use it in GitHub Desktop.
Save Velmm/92ec3986f0f0f02018c1ef2358ea8317 to your computer and use it in GitHub Desktop.
public class MainActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private RecyclerViewAdapter recyclerViewAdapter;
private List<Movie> movieList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
movieList = new ArrayList<>();
recyclerView = (RecyclerView)findViewById(R.id.recyclerView);
recyclerViewAdapter = new RecyclerViewAdapter(movieList);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(recyclerViewAdapter);
prepareMovie();
}
private void prepareMovie(){
Movie movie = new Movie("Star Wars The Last Jedi",R.drawable.star_war);
movieList.add(movie);
movie = new Movie("Coco",R.drawable.coco);
movieList.add(movie);
movie = new Movie("Justice League ",R.drawable.justice_league);
movieList.add(movie);
movie = new Movie("Thor: Ragnarok",R.drawable.thor_ragnarok);
movieList.add(movie);
recyclerViewAdapter.notifyDataSetChanged();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment