Guest User

Adapter

a guest
May 11th, 2021
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. public class CustomAdapter extends RecyclerView.Adapter<ViewHolder> {
  2.  
  3.     ListActivity listActivity;
  4.     List<Collection> collectionList;
  5.  
  6.  
  7.     public CustomAdapter(ListActivity listActivity, List<Collection> collectionList) {
  8.         this.listActivity = listActivity;
  9.         this.collectionList = collectionList;
  10.     }
  11.  
  12.     @NonNull
  13.     @NotNull
  14.     @Override
  15.     public ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup viewGroup, int i) {
  16.         View itemView = LayoutInflater.from(viewGroup.getContext())
  17.                 .inflate(R.layout.collection_layout, viewGroup, false);
  18.  
  19.  
  20.         ViewHolder viewHolder = new ViewHolder(itemView);
  21.  
  22.         viewHolder.setOnClickListener(new ViewHolder.ClickListener() {
  23.             @Override
  24.             public void onItemClick(View view, int position) {
  25.  
  26. //                показ данных в тосте при клике
  27.                 String title = collectionList.get(position).getTile();
  28.                 // image todo
  29.  
  30.  
  31.                 Toast.makeText(listActivity, title+"\n"
  32.                                 /// todo description
  33.                         , Toast.LENGTH_SHORT).show();
  34.             }
  35.  
  36.             @Override
  37.             public void onItemLongClick(View view, int position) {
  38.  
  39.             }
  40.         });
  41.         return viewHolder;
  42.     }
  43.  
  44.     @Override
  45.     public void onBindViewHolder(@NonNull @NotNull ViewHolder viewHolder, int position) {
  46.         viewHolder.rTitle.setText(collectionList.get(position).getTile());
  47.         //image TODO
  48.     }
  49.  
  50.     @Override
  51.     public int getItemCount() {
  52.         int a ;
  53.  
  54.         if(collectionList != null && !collectionList.isEmpty()) {
  55.  
  56.             a = collectionList.size();
  57.         }
  58.         else {
  59.  
  60.             a = 0;
  61.  
  62.         }
  63.  
  64.         return a;
  65.     }
  66. }
Add Comment
Please, Sign In to add comment