SHARE
TWEET

Untitled

a guest Jun 16th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class adapter extends RecyclerView.Adapter<adapter.viewHolder> {
  2.     private Context mContext;
  3.     private ArrayList<ItemActivity> mExampleList;
  4.  
  5.     public adapter(Context context, ArrayList<ItemActivity> exampleList)
  6.     {
  7.         mContext = context;
  8.         mExampleList = exampleList;
  9.     }
  10.  
  11.     @NonNull
  12.     @Override
  13.     public viewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
  14.     viewType) {
  15.             View v =
  16. LayoutInflater.from(mContext).inflate(R.layout.itemlayout, parent, false);
  17.         return new viewHolder(v);
  18.     }
  19.  
  20.     @Override
  21.     public void onBindViewHolder(@NonNull viewHolder holder, int position)
  22.     {
  23.         ItemActivity currentItem = mExampleList.get(position);
  24.  
  25.         String imageUrl = currentItem.getImageUrl();
  26.         String creatorName = currentItem.getCreator();
  27.         int likeCount = currentItem.getLikeCount();
  28.  
  29.         holder.mTextViewCreator.setText(creatorName);
  30.         holder.mTextViewLikes.setText("Likes: "+likeCount);
  31.  
  32.         Picasso.get(mContext).load(imageUrl).
  33.         fit().centerInside.into(holder.mImageView);//get() in picasso
  34.                                                      cannot be applied to
  35.                                                  (android.content.context)
  36.     }
  37.  
  38.     @Override
  39.     public int getItemCount() {
  40.         return mExampleList.size();
  41.     }
  42.  
  43.     public class viewHolder extends RecyclerView.ViewHolder
  44.     {
  45.         public ImageView mImageView;
  46.         public TextView mTextViewCreator;
  47.         public TextView mTextViewLikes;
  48.  
  49.         public viewHolder(@NonNull View itemView) {
  50.             super(itemView);
  51.             mTextViewCreator = itemView.findViewById(R.id.image_view);
  52.             mImageView = itemView.findViewById(R.id.text_view_creator);
  53.             mTextViewLikes = itemView.findViewById(R.id.text_view_likes);
  54.         }
  55.     }
  56.  
  57. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top