I have two ViewHolder
s with two different layout files. What I'd like to do is inflate one layout for a given ViewHolder
and then a second later, reinflate it with a different layout.
Here is some code:
class MyAdapter(context: Context,
myList: List<MyUiModel> = emptyList(),
private val clickListener: MyListener)
: RecyclerView.ViewHolder(context, myList) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
val layoutInflater = LayoutInflater.from(parent.context)
return when (viewType) {
TYPE_A ->
MyViewHolder.TypeAViewHolder(
layoutInflater.inflate(R.layout.type_a, parent, false), clickListener)
else -> MyViewHolder.TypeBViewHolder(
layoutInflater.inflate(R.layout.type_b, parent, false), clickListener)
}
}
So, whenever I need to instantiate TypeAViewHolder
, I would need to inflate type_a layout first, and then I would like to inflate type_b layout which will replace the type_a layout (there will be fade in/fade out animation between the two which I don't need help with). I am having a hard time inflating the layouts in sequence.
I tried the following with and without Thread.sleep(1000L)
in between.
TYPE_A -> {
MyViewHolder.TypeBViewHolder(
layoutInflater.inflate(R.layout.type_b, parent, false), clickListener)
MyViewHolder.TypeAViewHolder(
layoutInflater.inflate(R.layout.type_a, parent, false), clickListener)
}
But when I add log statements to my ViewHolder
s, only the last one listed (TypeAViewHolder
) gets bound to.
P.S. I know what I am trying to do is an odd thing to do but it is a requirement I have.
Thanks in advance!