Created
December 24, 2018 14:23
-
-
Save qichuan/53d2ae0e230905e641830f2dced98d95 to your computer and use it in GitHub Desktop.
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
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