I have two spinners in my RecyclerView. My first spinner is filled inside of the xml ->
<Spinner
android:id="@+id/itemspnReason"
android:layout_width="600dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:entries="@array/list_reasons"
/>
How ever with my second spinner it is not so easy. The spinner will show a number between 1 and the quantity available per item showed in the RecyclerView. Currently I have this code inside my onBindViewHolder ->
val modal = partsList[position]
holder.apply {
var i = 1
while (i <= modal.PQTY){ adapter.add(i.toString())
i++}
itemspnQTY.adapter = adapter
}
It works in getting to the desired number. The problem is each spinner is filled with all the data from each entry into the RecyclerView. For example if my first item had a size of 2 and my second item had a size of 4. Each of my spinner will contain the following: 1, 2, 1, 2, 3, 4.
So I need a way to clear the data after each entry or a better way to populate my spinner. My spinner is inside my item_list.xml for my RecyclerView. The easy solution is to do the same as my other spinner and create a static/hardcode entry. However I would like my spinner size to change based on how many items are available.
I have tried putting it inside my onCreateViewHolder and init. It did not solve problem.