flexbox-layout
flexbox-layout copied to clipboard
Cannot support multiple ViewHolder in Adapter
- [x] I have searched existing issues and confirmed this is not a duplicate
Issues and steps to reproduce
I create my Adapter that I use for my flex layout
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return when (viewType) {
EMPTY_INTEREST -> {
Log.i(InterestsAdapter::class.java.simpleName, "EMPTY_INTEREST")
val itemView = LayoutInflater.from(parent.context)
.inflate(R.layout.add_interests_button, parent, false)
EmptyInterestViewHolder(itemView)
}
INTEREST_ITEM -> {
Log.i(InterestsAdapter::class.java.simpleName, "ITEM_INTEREST")
val itemView = LayoutInflater.from(parent.context)
.inflate(R.layout.item_interest_profile, parent, false)
InterestViewHolder(itemView)
}
ADD_INTEREST -> {
Log.i(InterestsAdapter::class.java.simpleName, "ADD_INTEREST")
val itemView = LayoutInflater.from(parent.context)
.inflate(R.layout.add_interest, parent, false)
AddInterestViewHolder(itemView)
}
else -> throw RuntimeException("there is no type that matches the type $viewType + make sure your using types correctly")
}
}
Also I added my getItemViewType() to return my type of ViewHolder
override fun getItemViewType(position: Int): Int {
val vType = when {
position < dataSource.size -> INTEREST_ITEM
dataSource.size == 0 -> EMPTY_INTEREST
else -> ADD_INTEREST
}
Log.i(InterestsAdapter::class.java.simpleName, "type: $vType")
return vType
}
my Log display this:
2019-06-10 14:55:15.516 9303-9303/com.buddiefly.buddiefly I/InterestsAdapter: type: 1
2019-06-10 14:55:15.517 9303-9303/com.buddiefly.buddiefly I/InterestsAdapter: ITEM_INTEREST
2019-06-10 14:55:15.557 9303-9303/com.buddiefly.buddiefly I/InterestsAdapter: type: 1
2019-06-10 14:55:15.557 9303-9303/com.buddiefly.buddiefly I/InterestsAdapter: ITEM_INTEREST
2019-06-10 14:55:15.570 9303-9303/com.buddiefly.buddiefly I/InterestsAdapter: type: 1
2019-06-10 14:55:15.571 9303-9303/com.buddiefly.buddiefly I/InterestsAdapter: ITEM_INTEREST
2019-06-10 14:55:15.585 9303-9303/com.buddiefly.buddiefly I/InterestsAdapter: type: 2
2019-06-10 14:55:15.585 9303-9303/com.buddiefly.buddiefly I/InterestsAdapter: ADD_INTEREST
I have 3 items to display and the latest is a bottom that my adapter cannot display.
In my fragment I have this:
val layoutManager = FlexboxLayoutManager(activity)
layoutManager.flexDirection = FlexDirection.ROW
layoutManager.justifyContent = JustifyContent.FLEX_START
lookingForList.layoutManager = layoutManager
lookingForList.adapter = adapter
Note: I am using kotlinx not AndroidX
my recylcerView is this:
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/lookingForList" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
Expected behavior
Display the button ADD_INTEREST in my flex layout
Version of the flexbox library
0.3.2
I checked this issue on version 2.0.1 and everything works fine The example of code: https://github.com/sheckspir/PetOpenSource/tree/master/app/src/main/java/ru/sheckspir/petapplication/fragments/flexbox