For an onBindViewHolder function of mine, I'm trying to detect if a specific drawable is present within an ImageView but for some reason, the detection is not working properly. Why does the else part of the statement always get executed when the drawable clearly shows a down arrow and the first part of the statement never works? I've already followed this answer (using constantState) but it doesn't work for me.
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.mIVExpandCollapse.setOnClickListener {
when {
holder.mIVExpandCollapse.drawable.constantState == ContextCompat.getDrawable(holder.mIVExpandCollapse.context, R.drawable.ic_keyboard_arrow_down)!!.constantState -> {
Toast.makeText(holder.mIVExpandCollapse.context, "Hi there! This is a Toast.", Toast.LENGTH_LONG).show()
}
else -> {
Toast.makeText(holder.mIVExpandCollapse.context, "Hi there! This is not a Toast.", Toast.LENGTH_LONG).show()
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire