I am creating a RecyclerView which has an item with dynamic chips. I am looping through an array to set the text of the chip, this works fine but when I scroll the RecyclerView, more chips gets created
for (item in array) { val mChip: Chip = mActivity.layoutInflater.inflate(R.layout.item_chip, null, false) as Chip mChip.text = model val paddingDp = TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 10f, mActivity.resources.displayMetrics ).toInt() mChip.setPadding(paddingDp, 0, paddingDp, 0) mChip.setOnCloseIconClickListener { Toast.makeText(mActivity.applicationContext, absoluteAdapterPosition.toString()+ mChip.text,Toast.LENGTH_SHORT).show() } binding.chipsGroup.addView(mChip) } https://stackoverflow.com/questions/66123449/recyclerview-recreating-dynamic-chips-on-scroll February 10, 2021 at 12:55AM
没有评论:
发表评论