Guest User

Untitled

a guest
Nov 14th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity {
  2.  
  3. List<imagefull> lstBook;
  4. @Override
  5. protected void onCreate(Bundle savedInstanceState) {
  6. super.onCreate(savedInstanceState);
  7. setContentView(R.layout.activity_main);
  8.  
  9. lstBook = new ArrayList<>();
  10. lstBook.add(new imagefull(R.drawable.thevigitarian));
  11. lstBook.add(new imagefull(R.drawable.thewildrobot));
  12. lstBook.add(new imagefull(R.drawable.mariasemples));
  13. lstBook.add(new imagefull(R.drawable.themartian));
  14. lstBook.add(new imagefull(R.drawable.hediedwith));
  15. lstBook.add(new imagefull(R.drawable.thevigitarian));
  16. lstBook.add(new imagefull(R.drawable.thewildrobot));
  17. lstBook.add(new imagefull(R.drawable.mariasemples));
  18. lstBook.add(new imagefull(R.drawable.themartian));
  19. lstBook.add(new imagefull(R.drawable.hediedwith));
  20.  
  21. RecyclerView recyclerView = (RecyclerView)findViewById(R.id.recycler_view);
  22. RecyclerViewAdapter recyclerViewAdapter = new RecyclerViewAdapter(this,lstBook);
  23. recyclerView.setLayoutManager(new GridLayoutManager(this,3));
  24. recyclerView.setAdapter(recyclerViewAdapter);
  25. }
  26.  
  27. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  28. xmlns:app="http://schemas.android.com/apk/res-auto"
  29. xmlns:tools="http://schemas.android.com/tools"
  30. android:layout_width="match_parent"
  31. android:layout_height="match_parent"
  32. tools:context=".MainActivity"
  33. android:padding="8dp">
  34.  
  35. <android.support.v7.widget.RecyclerView
  36. android:id="@+id/recycler_view"
  37. android:layout_width="match_parent"
  38. android:layout_height="match_parent">
  39. </android.support.v7.widget.RecyclerView>
  40.  
  41. public RecyclerViewAdapter(Context mContext, List<imagefull> mData) {
  42. this.mContext = mContext;
  43. this.mData = mData;
  44. }
  45.  
  46.  
  47. @NonNull
  48. @Override
  49. public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
  50.  
  51. View view;
  52. LayoutInflater minflater =LayoutInflater.from(mContext);
  53. view = minflater.inflate(R.layout.card_view, parent, false);
  54. return new MyViewHolder(view);
  55. }
  56.  
  57. @Override
  58. public void onBindViewHolder( MyViewHolder Holder, final int position) {
  59. Holder.imageView.setImageResource(mData.get(position).getThumbnail());
  60. Holder.cardView.setOnClickListener(new View.OnClickListener() {
  61. @Override
  62. public void onClick(View v) {
  63. String action;
  64. Intent intent = new Intent(mContext,FullScreenImagView.class);
  65. intent.putExtra("Thumbnail",mData.get(position).getThumbnail());
  66. mContext.startActivity(intent);
  67. }
  68. });
  69. }
  70.  
  71. @Override
  72. public int getItemCount() {
  73. return mData.size();
  74. }
  75.  
  76. public static class MyViewHolder extends RecyclerView.ViewHolder
  77. {
  78. ImageView imageView;
  79. CardView cardView ;
  80.  
  81. public MyViewHolder(View itemView) {
  82. super(itemView);
  83.  
  84. imageView = (ImageView) itemView.findViewById(R.id.img_view);
  85. cardView = (CardView)itemView.findViewById(R.id.cardview);
  86. }
  87. }
  88.  
  89. public class FullScreenImagView extends AppCompatActivity {
  90.  
  91. ImageView full_img_view;
  92. @Override
  93. protected void onCreate(Bundle savedInstanceState) {
  94. super.onCreate(savedInstanceState);
  95. setContentView(R.layout.activity_full_screen_imag_view);
  96.  
  97. full_img_view = findViewById(R.id.full_img_view);
  98.  
  99. Intent intent = getIntent();
  100. int image = intent.getExtras().getInt("Thumbnail");
  101. full_img_view.setImageResource(image);
  102.  
  103. }
Add Comment
Please, Sign In to add comment