Skip to content

Instantly share code, notes, and snippets.

@qichuan
Created December 24, 2018 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qichuan/53d2ae0e230905e641830f2dced98d95 to your computer and use it in GitHub Desktop.
Save qichuan/53d2ae0e230905e641830f2dced98d95 to your computer and use it in GitHub Desktop.
class LessNumerousGCRecyclerViewAdapter(private val context: Context,
private val numbers: List<Int>): RecyclerView.Adapter<NumerousGCViewHolder>() {
val bitBitmap = BitmapFactory.decodeResource(context.resources, R.drawable.big_bitmap)
val smallBitmap = BitmapFactory.decodeResource(context.resources, R.drawable.small_bitmap)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NumerousGCViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_numerous_gc, parent, false)
return NumerousGCViewHolder(view)
}
override fun getItemCount(): Int {
return numbers.size
}
override fun onBindViewHolder(vh: NumerousGCViewHolder, position: Int) {
vh.textView.text = position.toString()
//Reuse bitmap
val bitmap = if(position % 2 == 0) bitBitmap else smallBitmap
vh.imageView.setImageBitmap(bitmap)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment