Skip to content

Instantly share code, notes, and snippets.

@qichuan
Last active December 24, 2018 09:13
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/035223700889ef9396f524c9d8474c5d to your computer and use it in GitHub Desktop.
Save qichuan/035223700889ef9396f524c9d8474c5d to your computer and use it in GitHub Desktop.
class NumerousGCActivity: AppCompatActivity() {
val NO_OF_VIEWS = 100000
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_numerous_gc)
btn_start.setOnClickListener {
setupRecyclerView()
}
}
private fun setupRecyclerView() {
val numbers = arrayOfNulls<Int>(NO_OF_VIEWS).mapIndexed { index, _ -> index }
recyclerView.layoutManager = LinearLayoutManager(this)
recyclerView.adapter = NumerousGCRecyclerViewAdapter(numbers)
}
}
class NumerousGCRecyclerViewAdapter(private val numbers: List<Int>): RecyclerView.Adapter<NumerousGCViewHolder>() {
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()
//Create bitmap from resource
val bitmap = if(position % 2 == 0)
BitmapFactory.decodeResource(vh.imageView.context.resources, R.drawable.big_bitmap)
else
BitmapFactory.decodeResource(vh.imageView.context.resources, R.drawable.small_bitmap)
vh.imageView.setImageBitmap(bitmap)
}
}
class NumerousGCViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
var textView: TextView = itemView.findViewById(R.id.text_view)
var imageView: ImageView = itemView.findViewById(R.id.image_view)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment