Advertisement
mouhsineelachbi

mainActivty

Apr 1st, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.07 KB | None | 0 0
  1. package com.example.test;
  2.  
  3. import android.content.Context;
  4. import android.os.Bundle;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.support.v7.widget.DefaultItemAnimator;
  7. import android.support.v7.widget.LinearLayoutManager;
  8. import android.support.v7.widget.RecyclerView;
  9. import android.support.v7.widget.Toolbar;
  10. import android.view.GestureDetector;
  11. import android.view.MotionEvent;
  12. import android.view.View;
  13. import android.widget.Toast;
  14.  
  15. import java.util.ArrayList;
  16. import java.util.List;
  17.  
  18. public class MainActivity extends AppCompatActivity {
  19.     private List<Movie> movieList = new ArrayList<>();
  20.     private RecyclerView recyclerView;
  21.     private MoviesAdapter mAdapter;
  22.  
  23.     @Override
  24.     protected void onCreate(Bundle savedInstanceState) {
  25.         super.onCreate(savedInstanceState);
  26.         setContentView(R.layout.activity_main);
  27.  
  28.         recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
  29.  
  30.         mAdapter = new MoviesAdapter(movieList);
  31.  
  32.         RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
  33.         recyclerView.setLayoutManager(mLayoutManager);
  34.  
  35.          recyclerView.setItemAnimator(new DefaultItemAnimator());
  36.         recyclerView.setAdapter(mAdapter);
  37.  
  38.         prepareMovieData();
  39.     }
  40.  
  41.     private void prepareMovieData() {
  42.         Movie movie = new Movie("Mad Max: Fury Road", "Action & Adventure", "2015");
  43.         movieList.add(movie);
  44.  
  45.         movie = new Movie("Inside Out", "Animation, Kids & Family", "2015");
  46.         movieList.add(movie);
  47.  
  48.         movie = new Movie("Star Wars: Episode VII - The Force Awakens", "Action", "2015");
  49.         movieList.add(movie);
  50.  
  51.         movie = new Movie("Shaun the Sheep", "Animation", "2015");
  52.         movieList.add(movie);
  53.  
  54.         movie = new Movie("The Martian", "Science Fiction & Fantasy", "2015");
  55.         movieList.add(movie);
  56.  
  57.         movie = new Movie("Mission: Impossible Rogue Nation", "Action", "2015");
  58.         movieList.add(movie);
  59.  
  60.         movie = new Movie("Up", "Animation", "2009");
  61.         movieList.add(movie);
  62.  
  63.         movie = new Movie("Star Trek", "Science Fiction", "2009");
  64.         movieList.add(movie);
  65.  
  66.         movie = new Movie("The LEGO Movie", "Animation", "2014");
  67.         movieList.add(movie);
  68.  
  69.         movie = new Movie("Iron Man", "Action & Adventure", "2008");
  70.         movieList.add(movie);
  71.  
  72.         movie = new Movie("Aliens", "Science Fiction", "1986");
  73.         movieList.add(movie);
  74.  
  75.         movie = new Movie("Chicken Run", "Animation", "2000");
  76.         movieList.add(movie);
  77.  
  78.         movie = new Movie("Back to the Future", "Science Fiction", "1985");
  79.         movieList.add(movie);
  80.  
  81.         movie = new Movie("Raiders of the Lost Ark", "Action & Adventure", "1981");
  82.         movieList.add(movie);
  83.  
  84.         movie = new Movie("Goldfinger", "Action & Adventure", "1965");
  85.         movieList.add(movie);
  86.  
  87.         movie = new Movie("Guardians of the Galaxy", "Science Fiction & Fantasy", "2014");
  88.         movieList.add(movie);
  89.  
  90.         mAdapter.notifyDataSetChanged();
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement