Created
May 11, 2018 10:58
-
-
Save ashishkudale/d75c82b1d1df923441e699482d2b85ad to your computer and use it in GitHub Desktop.
Adapter for chapter list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ChapterAdapter extends RecyclerView.Adapter<ChapterAdapter.CustomViewHolder> { | |
private Context context; | |
private ArrayList<Chapter> chapters; | |
private LayoutInflater inflater; | |
public ChapterAdapter(Context context, ArrayList<Chapter> chapters) { | |
this.context = context; | |
this.chapters = chapters; | |
this.inflater = LayoutInflater.from(context); | |
} | |
@Override | |
public CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |
View view; | |
view = inflater.inflate(R.layout.single_chapter, parent, false); | |
return new CustomViewHolder(view); | |
} | |
@Override | |
public void onBindViewHolder(CustomViewHolder holder, int position) { | |
Chapter chapter = chapters.get(position); | |
holder.tvChapterName.setText(chapter.chapterName); | |
Picasso.get().load(chapter.imageUrl).into(holder.ivChapter); | |
} | |
@Override | |
public int getItemCount() { | |
return chapters.size(); | |
} | |
public class CustomViewHolder extends RecyclerView.ViewHolder { | |
public ImageView ivChapter; | |
public TextView tvChapterName; | |
public CustomViewHolder(View itemView) { | |
super(itemView); | |
tvChapterName = (TextView) itemView.findViewById(R.id.tvChapterName); | |
ivChapter = (ImageView) itemView.findViewById(R.id.ivChapter); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment