I have a checkbox and textview and I want to set the visibility of textview based on isChecked of the checkbox, can that be done using databinding in xml file directly ?
EDIT
class SquareCheckBox #JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyle: Int = 0) : ConstraintLayout (context, attrs, defStyle){
private var layout: ConstraintLayout
private var checkImageView : ImageView
private var iconImageView : ImageView
private var titleTextView : TextView
var isChecked : Boolean = (false)
var iconImage : Int = -1
var title : String = ""
init {
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val view = inflater.inflate(R.layout.item_square_checkbox, this, true)
layout = view.layout
checkImageView = view.checkImageView
iconImageView = view.iconImageView
titleTextView = view.titleTextView
initAttributes(attrs)
applyUIChanges()
}
fun initAttributes(attrs: AttributeSet?){
attrs?.let {
val typedArray = context.obtainStyledAttributes(it, R.styleable.square_checkbox_attributes, 0, 0)
isChecked = typedArray.getBoolean(R.styleable.square_checkbox_attributes_isChecked, false)
iconImage = typedArray.getResourceId(R.styleable.square_checkbox_attributes_iconImage, -1)
title = typedArray.getString(R.styleable.square_checkbox_attributes_title)
typedArray.recycle()
}
}
fun applyUIChanges () {
if (isChecked) {
checkImageView.visibility = View.VISIBLE
titleTextView.setTextColor(resources.getColor(android.R.color.black))
layout.setBackgroundResource(R.drawable.xml_square_checkbox_selected)
} else {
checkImageView.visibility = View.INVISIBLE
titleTextView.setTextColor(resources.getColor(R.color.lightGray))
layout.setBackgroundResource(R.drawable.xml_square_checkbox_unselected)
}
if (iconImage != -1) {
iconImageView.setImageResource(iconImage)
}
titleTextView.setText(title)
}
fun performOnClick () {
isChecked = !isChecked
applyUIChanges()
}
companion object {
#JvmStatic
#BindingAdapter("app:isChecked")
fun setIsChecked(view: SquareCheckBox, checked: Boolean) {
view.isChecked = checked
view.applyUIChanges()
}
#InverseBindingAdapter(attribute = "app:isChecked")
#JvmStatic fun getIsChecked(view: SquareCheckBox) : Boolean {
return view.isChecked
}
#BindingAdapter("app:isCheckedAttrChanged")
#JvmStatic fun setListeners(
view: SquareCheckBox,
attrChange: InverseBindingListener) {
}
}
}
and this is the xml
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/xml_square_checkbox_unselected">
<ImageView
android:id="#+id/checkImageView"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="#drawable/ic_ckeck"
android:tint="#color/colorPrimary"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="4dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"/>
<ImageView
android:id="#+id/iconImageView"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_centerHorizontal="true"
android:src="#drawable/ic_placeholder_squre" app:layout_constraintTop_toBottomOf="#+id/checkImageView"
app:layout_constraintBottom_toTopOf="#+id/titleTextView"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="8dp"
android:layout_marginRight="8dp" app:layout_constraintStart_toStartOf="parent"
android:layout_marginLeft="8dp" android:layout_marginStart="8dp"/>
<TextView
android:id="#+id/titleTextView"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_below="#id/iconImageView"
android:ellipsize="end"
android:gravity="center"
android:lines="2"
android:text="#string/text"
android:maxLines="2"
android:textColor="#android:color/black"
android:textSize="12sp"
android:layout_marginBottom="4dp"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/iconImageView"
app:layout_constraintEnd_toEndOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</merge>
EDIT2
I have also added a variable in view model and try to set the visibility based on it
<com.google.android.material.textfield.TextInputLayout
android:visibility="#{viewModel.doNotDisturbEnabled ? View.GONE : View.VISIBLE}"
android:id="#+id/from_textinput"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:fontFamily="sans-serif"
android:hint="#string/from"
android:textColor="#color/colorDarkGrey"
android:textColorHint="#color/colorDarkGrey"
android:textSize="12sp"
android:textStyle="normal"
app:boxCornerRadiusBottomEnd="5dp"
app:boxCornerRadiusBottomStart="5dp"
app:boxCornerRadiusTopEnd="5dp"
app:boxCornerRadiusTopStart="5dp"
app:boxStrokeColor="#color/colorPrimary"
app:boxStrokeWidth="3dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/doNotDisturbCheckBox"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintEnd_toStartOf="#+id/to_textinput">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/from_textedit"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</com.google.android.material.textfield.TextInputLayout>
but it still not working
yes you can do this using data binding for that you need to DataBinding Obserable and make your own #Binder for your model and the change the value of this observed property on the change of status of your checkbox status
Related
I have an activity that has two fragments. I have created a layout that is reusable as following:
Here is the xml of custom layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/tvFormTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black1"
android:textSize="#dimen/ssp_10"
android:visibility="visible"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Email" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/clForm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/sdp_4"
android:background="#drawable/sh_all_round_form"
android:paddingStart="#dimen/sdp_12"
android:paddingEnd="#dimen/sdp_12"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tvFormTitle">
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/etForm"
style="#style/et_form"
android:layout_width="0dp"
android:layout_weight="1"
app:layout_constraintEnd_toStartOf="#+id/ivSwitchPassword"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/ivSwitchPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingStart="#dimen/sdp_8"
android:paddingTop="#dimen/sdp_8"
android:paddingEnd="#dimen/sdp_2"
android:paddingBottom="#dimen/sdp_8"
android:src="#drawable/ic_eye"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="#+id/etForm"
app:layout_constraintEnd_toStartOf="#+id/ivCancel"
app:layout_constraintTop_toTopOf="#+id/etForm" />
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/ivCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingStart="#dimen/sdp_12"
android:paddingTop="#dimen/sdp_12"
android:paddingBottom="#dimen/sdp_12"
android:src="#drawable/white_close"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="#+id/etForm"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/etForm"
app:tint="#color/grey_shade5" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/tvMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/sdp_5"
android:textColor="#color/colorError"
android:textSize="#dimen/ssp_10"
android:visibility="visible"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/clForm"
tools:text="This field is required" />
</androidx.constraintlayout.widget.ConstraintLayout>
I am using this custom la in Fragment A as follow:
<include
android:id="#+id/email"
layout="#layout/layout_form_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/sdp_36"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tvDescription" />
<include
android:id="#+id/password"
layout="#layout/layout_form_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/sdp_12"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/email" />
I am using Fragment navigation to move from Fragment A to B. Entering values in email and password and move to Fragment B and get back to Fragment A by pressing back or navigateUp(). Email field contains the value of password field.
Edit:
Same layout it used in Custom Compound class as following getting same issue.
class FormView #JvmOverloads
constructor(
private val ctx: Context,
private val attributeSet: AttributeSet? = null,
private val defStyleAttr: Int = 0
) : ConstraintLayout(ctx, attributeSet, defStyleAttr) {
private var formTitle = ""
private var passwordType = false
private var showMessage = false
init {
val inflater = ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val attributes = ctx.obtainStyledAttributes(attributeSet, R.styleable.FormView)
attributes.getString(R.styleable.FormView_formTitle)?.let { formTitle = it }
passwordType = attributes.getBoolean(R.styleable.FormView_passwordType, passwordType)
showMessage = attributes.getBoolean(R.styleable.FormView_showErrorMessage, false)
attributes.recycle()
inflater.inflate(R.layout.layout_form_edittext, this)
setTitle(formTitle)
setPasswordType(passwordType)
errorMessageVisibility(showMessage)
borderVisibility(false)
ivSwitchPassword.setOnClickListener {
updatePasswordVisibility()
}
ivCancel.setOnClickListener {
etForm.text?.clear()
clearError()
}
}
fun showError(msg: String) {
msg?.let {
tvMessage.text = it
cancelBtnVisibility(true)
errorMessageVisibility(true)
borderVisibility(true)
}
}
fun clearError() {
tvMessage.text = ""
cancelBtnVisibility(false)
errorMessageVisibility(false)
borderVisibility(false)
}
private fun errorMessageVisibility(flag: Boolean) {
if (flag) tvMessage.visible() else tvMessage.gone()
}
private fun cancelBtnVisibility(flag: Boolean) {
if (flag) ivCancel.visible() else ivCancel.gone()
}
private fun borderVisibility(flag: Boolean) {
val drawable = clForm.background as GradientDrawable
if(flag) drawable.setStroke(1, Color.parseColor("#c32329"))
else drawable.setStroke(0, Color.TRANSPARENT)
}
fun setPasswordType(passwordType: Boolean) {
if(!passwordType) ivSwitchPassword.gone()
else {
ivSwitchPassword.visible()
etForm.inputType = InputTypeUtils.getInputTypeByProperty("textPassword")
}
}
fun setTitle(title: String) {
tvFormTitle.text = title
}
private fun updatePasswordVisibility() {
if (etForm.transformationMethod is PasswordTransformationMethod) {
etForm.transformationMethod = null
} else {
etForm.transformationMethod = PasswordTransformationMethod()
}
etForm.setSelection(etForm.length())
}
}
This is because include edit text has one id for both field, solution is to generate new id add this code on your onViewCreated method:
email.etForm.id = View.generateViewId()
password.etForm.id = View.generateViewId()
I am trying to make a grid layout with expandable cards, but the problem is that when a card is expanded, its height gets bigger and so does the height of the other cards in the row (to match the height of the first card), but when the card is collapsed back, the height of all the cards does not change as if they were expanded. Anyone knows what could be the problem?
EDIT :
recyclerview_item.xml
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="#color/misty_rose"
android:layout_margin="8dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Media -->
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_gravity="center_horizontal"
android:padding="8dp"
android:contentDescription="Photo"
android:src="#drawable/unsplash"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="#color/isabelline"
/>
<!-- Title, secondary and supporting text -->
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/misty_rose"
app:layout_constraintTop_toBottomOf="#+id/imageView"
android:padding="8dp">
<TextView
android:id="#+id/textViewCode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Code"
android:textAppearance="?attr/textAppearanceHeadline6"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatImageButton
android:id="#+id/iconExpandCard"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="8dp"
android:src="#drawable/ic_baseline_expand_more_36"
android:background="?attr/selectableItemBackgroundBorderless"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<TextView
android:id="#+id/textViewDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Description"
android:textAppearance="?attr/textAppearanceBody1"
android:textColor="?android:attr/textColorSecondary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textViewCode" />
<TextView
android:id="#+id/textViewPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Price"
android:textAppearance="?attr/textAppearanceBody1"
android:textColor="?android:attr/textColorSecondary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textViewDescription"/>
<TextView
android:id="#+id/textViewComment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Comment"
android:textAppearance="?attr/textAppearanceBody1"
android:textColor="?android:attr/textColorSecondary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textViewPrice"
android:visibility="gone"/>
<!-- Buttons -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="8dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textViewComment">
<com.google.android.material.button.MaterialButton
android:id="#+id/buttonMinusArticle"
style="?attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:width="88dp"
android:minWidth="40dp"
android:backgroundTint="#color/purple_200"
android:text="#string/minus"
android:textColor="#color/white" />
<EditText
android:id="#+id/editNumberOfProducts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="16dp"
android:inputType="numberDecimal|number"
android:text="#string/zero"
android:textAppearance="?attr/textAppearanceBody1"
android:textColor="?android:attr/textColorSecondary"
android:textSize="18sp" />
<com.google.android.material.button.MaterialButton
android:id="#+id/buttonPlusArticle"
style="?attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="88dp"
android:minWidth="40dp"
android:backgroundTint="#color/purple_200"
android:text="#string/plus"
android:textColor="#color/white" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
And in ProductListAdapter.kt (the important part is in expandButton.setOnClickListener() ):
class ProductListAdapter() : ListAdapter<Product, ProductListAdapter.ProductViewHolder>(ProductsComparator()) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ProductViewHolder {
return ProductViewHolder.create(parent)
}
override fun onBindViewHolder(holder: ProductViewHolder, position: Int) {
val current = getItem(position)
holder.bind(current!!)
}
class ProductViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val productItemView: TextView = itemView.findViewById(R.id.textViewCode)
private val productDescription : TextView = itemView.findViewById(R.id.textViewDescription)
private val productPrice : TextView = itemView.findViewById(R.id.textViewPrice)
fun bind(product: Product) {
productItemView.text = product.code
//productDescription.text = product.description
//productPrice.text = "Price " + product.client_price.toString()
}
companion object {
val mapOfProducts :HashMap<String, Int> = hashMapOf<String, Int>()
fun create(parent: ViewGroup): ProductViewHolder {
val view: View = LayoutInflater.from(parent.context)
.inflate(R.layout.recyclerview_item, parent, false)
val minusButton : Button = view.findViewById(R.id.buttonMinusArticle)
val plusButton : Button = view.findViewById(R.id.buttonPlusArticle)
val productItemViewCode: TextView = view.findViewById(R.id.textViewCode)
val expandButton : androidx.appcompat.widget.AppCompatImageButton = view.findViewById(R.id.iconExpandCard)
val commentView : TextView = view.findViewById(R.id.textViewComment)
val cardView : CardView = view.findViewById(R.id.cardView)
expandButton.setOnClickListener{
if (commentView.visibility == View.GONE){
TransitionManager.beginDelayedTransition(cardView, AutoTransition())
commentView.visibility = View.VISIBLE
expandButton.setImageResource(R.drawable.ic_baseline_expand_less_36)
} else {
TransitionManager.beginDelayedTransition(cardView, AutoTransition())
commentView.visibility = View.GONE
expandButton.setImageResource(R.drawable.ic_baseline_expand_more_36)
}
}
val editNumberOfProducts: EditText = view.findViewById(R.id.editNumberOfProducts)
editNumberOfProducts.doAfterTextChanged {
val code = productItemViewCode.text.toString()
if (it.isNullOrBlank()) {
modifyText("0", view)
mapOfProducts.remove(code)
return#doAfterTextChanged
}
val originalText = it.toString()
try {
val number = originalText.toInt()
val numberText = originalText.toInt().toString()
if (originalText != numberText) {
modifyText(numberText, view)
}
if (number > 0) {
mapOfProducts[code] = number
d("CodeOfView", "$code $number")
}else {
mapOfProducts.remove(code)
}
} catch (e: Exception) {
modifyText("0", view)
mapOfProducts.remove(code)
}
}
minusButton.setOnClickListener {
var number = editNumberOfProducts.text.toString().toInt()
if (number>0) {
number -= 1
modifyText(number.toString(), view)
}
}
plusButton.setOnClickListener {
//val code = productItemViewCode.text.toString()
var number = editNumberOfProducts.text.toString().toInt()
number += 1
modifyText(number.toString(), view)
}
return ProductViewHolder(view)
}
private fun modifyText(numberText: String, view: View) {
val editNumberOfProducts = view.findViewById<EditText>(R.id.editNumberOfProducts)
editNumberOfProducts.setText(numberText)
editNumberOfProducts.setSelection(numberText.length)
}
}
}
class ProductsComparator : DiffUtil.ItemCallback<Product>() {
override fun areItemsTheSame(oldItem: Product, newItem: Product): Boolean {
return oldItem === newItem
}
override fun areContentsTheSame(oldItem: Product, newItem: Product): Boolean {
return oldItem.code == newItem.code
}
}
}
Example with images of the problem
I was facing a same issue, in my case it was vertical expandable cards and I managed to solve it by using
Adapter.notifyDataSetChanged()
in the right place.
I can see a flicker within my recycler view right at the top. The flicker seems to resemble the top lines of my drawable shapes in the recycler view item.xml. I have made various adjustments to lines and other things to see if I could prevent the flicker but nothing appears to be working.
Here is my code;
Activity
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".ScoreHistory">
<TextView
android:id="#+id/textView_history_title"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:gravity="center|center_horizontal|center_vertical"
android:padding="5dp"
android:text="#string/GameHistory_Title"
android:textAlignment="gravity"
android:textColor="#color/lime"
android:textStyle="bold"
app:autoSizeTextType="uniform"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/RV_scorehistory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView_history_title" />
</androidx.constraintlayout.widget.ConstraintLayout>
My item.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#drawable/rv_lines"
android:gravity="center_vertical">
<TextView
android:id="#+id/TV_RV_ID"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:gravity="center"
android:textAlignment="center"
app:layout_constraintEnd_toStartOf="#+id/TV_RV_DIFFICULTY"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/TV_RV_DIFFICULTY"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:gravity="center"
android:textAlignment="center"
app:layout_constraintBaseline_toBaselineOf="#+id/TV_RV_ID"
app:layout_constraintEnd_toStartOf="#+id/TV_RV_SUMTYPE"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_weight="4"
app:layout_constraintStart_toEndOf="#+id/TV_RV_ID" />
<TextView
android:id="#+id/TV_RV_SUMTYPE"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:gravity="center"
android:textAlignment="center"
app:layout_constraintBaseline_toBaselineOf="#+id/TV_RV_DIFFICULTY"
app:layout_constraintEnd_toStartOf="#+id/TV_RV_OutOfText"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_weight="3.5"
app:layout_constraintStart_toEndOf="#+id/TV_RV_DIFFICULTY" />
<TextView
android:id="#+id/TV_RV_OutOfText"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:gravity="center"
android:text="#string/score_text"
app:layout_constraintBaseline_toBaselineOf="#+id/TV_RV_SUMTYPE"
app:layout_constraintEnd_toStartOf="#+id/TV_RV_SCORE"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_weight="2"
app:layout_constraintStart_toEndOf="#+id/TV_RV_SUMTYPE" />
<TextView
android:id="#+id/TV_RV_SCORE"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="6dp"
android:gravity="center"
android:textAlignment="center"
android:textStyle="bold"
app:layout_constraintBaseline_toBaselineOf="#+id/TV_RV_OutOfText"
app:layout_constraintEnd_toStartOf="#+id/TV_RV_QCOUNT_TEXT"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_weight="1.5"
app:layout_constraintStart_toEndOf="#+id/TV_RV_OutOfText" />
<TextView
android:id="#+id/TV_RV_QCOUNT_TEXT"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:gravity="center"
android:text="#string/questions_text"
android:textAlignment="gravity"
android:textStyle="bold"
app:layout_constraintBaseline_toBaselineOf="#+id/TV_RV_SCORE"
app:layout_constraintEnd_toStartOf="#+id/TV_RV_QCOUNT"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_weight=".75"
app:layout_constraintStart_toEndOf="#+id/TV_RV_SCORE" />
<TextView
android:id="#+id/TV_RV_QCOUNT"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:background="#drawable/target_icon"
android:gravity="center"
android:textAlignment="center"
android:textStyle="bold"
app:layout_constraintBaseline_toBaselineOf="#+id/TV_RV_QCOUNT_TEXT"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_weight="1.5"
app:layout_constraintStart_toEndOf="#+id/TV_RV_QCOUNT_TEXT" />
</androidx.constraintlayout.widget.ConstraintLayout>
I set background resources here in my adapter
class ScoreHistoryAdaptor : ListAdapter<SavedScores, ScoreHistoryAdaptor.SavedScoreViewHolder>(WordsComparator()) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SavedScoreViewHolder {
return SavedScoreViewHolder.create(parent)
}
override fun onBindViewHolder(holder: SavedScoreViewHolder, position: Int) {
val current = getItem(position)
holder.bind(current.id,current.difficulty,current.sumtype,current.questioncount,current.answeredcorrectly)
}
class SavedScoreViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val IDItemView: TextView = itemView.findViewById(R.id.TV_RV_ID)
private val DiffultyItemView: TextView = itemView.findViewById(R.id.TV_RV_DIFFICULTY)
private val SumTypeItemView: TextView = itemView.findViewById(R.id.TV_RV_SUMTYPE)
private val qCountItemView: TextView = itemView.findViewById(R.id.TV_RV_QCOUNT)
private val ScoreItemView: TextView = itemView.findViewById(R.id.TV_RV_SCORE)
private var DIFFCODE = ""
private var SUMTYPECODE = ""
val myContext = SumTypeItemView.context
fun bind(ID: Int?,DIFFICULTY:String?,SUMTYPE:String?,QC:Int?,SCORE:Int?) {
IDItemView.text = ID.toString()
when (DIFFICULTY) {
myContext.resources.getString(R.string.diffLVL1) -> {DIFFCODE = DIFFICULTY; DiffultyItemView.setBackgroundResource(R.drawable.diff_easy_icon)}
myContext.resources.getString(R.string.diffLVL2) -> {DIFFCODE = DIFFICULTY ; DiffultyItemView.setBackgroundResource(R.drawable.diff_normal_icon)}
myContext.resources.getString(R.string.diffLVL3) -> {DIFFCODE = DIFFICULTY; DiffultyItemView.setBackgroundResource(R.drawable.diff_hard_icon) }
myContext.resources.getString(R.string.diffLVL4) -> {DIFFCODE = DIFFICULTY ; DiffultyItemView.setBackgroundResource(R.drawable.diff_impossible_icon)}
myContext.resources.getString(R.string.random) -> {DIFFCODE = DIFFICULTY ; DiffultyItemView.setBackgroundResource(R.drawable.diff_random_icon)}
}
DiffultyItemView.text = DIFFCODE
when (SUMTYPE) {
myContext.resources.getString(R.string.catMulti) -> {SUMTYPECODE = myContext.resources.getString(R.string.multi_symbol) }
myContext.resources.getString(R.string.catAdd) -> {SUMTYPECODE = myContext.resources.getString(R.string.add_symbol)}
myContext.resources.getString(R.string.catSub) -> {SUMTYPECODE = myContext.resources.getString(R.string.sub_symbol)}
myContext.resources.getString(R.string.catDiv) -> {SUMTYPECODE = myContext.resources.getString(R.string.div_symbol)}
myContext.resources.getString(R.string.catSqrR) -> {SUMTYPECODE = myContext.resources.getString(R.string.sqr_symbol) + "n"}
myContext.resources.getString(R.string.catSqrD) -> {SUMTYPECODE = "n" + myContext.resources.getString(R.string.sqrd_symbol)}
myContext.resources.getString(R.string.catCubeR) -> {SUMTYPECODE = myContext.resources.getString(R.string.cuber_symbol) + "n"}
myContext.resources.getString(R.string.catCubeD) -> {SUMTYPECODE = "n" + myContext.resources.getString(R.string.cubed_symbol)}
myContext.resources.getString(R.string.random) -> {SUMTYPECODE = myContext.resources.getString(R.string.random)}
}
when (IsScoreLessThanTarget(SCORE!!.toInt(),QC!!.toInt())){
true ->{ScoreItemView.setBackgroundResource(R.drawable.somewrong_icon)}
false ->{ScoreItemView.setBackgroundResource(R.drawable.allcorrect_icon)}
}
SumTypeItemView.setBackgroundResource(R.drawable.sumtype_icon)
SumTypeItemView.text = SUMTYPECODE
qCountItemView.text = QC.toString()
ScoreItemView.text = SCORE.toString()
}
companion object {
fun create(parent: ViewGroup): SavedScoreViewHolder {
val view: View = LayoutInflater.from(parent.context)
.inflate(R.layout.row_item, parent, false)
return SavedScoreViewHolder(view)
}
}
}
class WordsComparator : DiffUtil.ItemCallback<SavedScores>() {
override fun areItemsTheSame(oldItem: SavedScores, newItem: SavedScores): Boolean {
return oldItem.id == newItem.id
}
override fun areContentsTheSame(oldItem: SavedScores, newItem: SavedScores): Boolean {
return oldItem == newItem
}
}
}
private fun IsScoreLessThanTarget(score:Int,target:Int): Boolean{
return score < target
}
In another view using scrollview I get the same
Your issue is arising because in your my_item.xml
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="55dp" <---- Fixed Height
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#ae7f9c"
android:gravity="center_vertical">
and in your textviews like this one,
<TextView
android:id="#+id/TV_RV_ID"
android:layout_width="0dp"
android:layout_height="match_parent" <------ this hiding the background try using wrap_content
android:layout_margin="0dp"
android:gravity="center"
android:textAlignment="center"
app:layout_constraintEnd_toStartOf="#+id/TV_RV_DIFFICULTY"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
To solve this,
Try not giving a fixed height from my_item.xml container, use wrap_content
Add padding to the container constaintlayout
add android:layout_height="wrap_content" to your text views and center_vertical them,
then your issue will resolve, hope this helps
try not giving a fixed height to the container
I have created a custom view as following
class SquareCheckBox #JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyle: Int = 0) : ConstraintLayout (context, attrs, defStyle){
private var layout: ConstraintLayout
private var checkImageView : ImageView
private var iconImageView : ImageView
private var titleTextView : TextView
var isChecked : Boolean = false
var iconImage : Int = -1
var title : String = ""
init {
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val view = inflater.inflate(R.layout.item_square_checkbox, this, true)
layout = view.layout
checkImageView = view.checkImageView
iconImageView = view.iconImageView
titleTextView = view.titleTextView
initAttributes(attrs)
applyUIChanges()
addAction()
}
fun initAttributes(attrs: AttributeSet?){
attrs?.let {
val typedArray = context.obtainStyledAttributes(it, R.styleable.square_checkbox_attributes, 0, 0)
isChecked = typedArray.getBoolean(R.styleable.square_checkbox_attributes_isChecked, false)
iconImage = typedArray.getResourceId(R.styleable.square_checkbox_attributes_iconImage, -1)
title = typedArray.getString(R.styleable.square_checkbox_attributes_title)
typedArray.recycle()
}
}
fun applyUIChanges () {
if (isChecked) {
checkImageView.visibility = View.VISIBLE
titleTextView.setTextColor(resources.getColor(android.R.color.black))
layout.setBackgroundResource(R.drawable.xml_square_checkbox_selected)
} else {
checkImageView.visibility = View.INVISIBLE
titleTextView.setTextColor(resources.getColor(R.color.lightGray))
layout.setBackgroundResource(R.drawable.xml_square_checkbox_unselected)
}
if (iconImage != -1) {
iconImageView.setImageResource(iconImage)
}
titleTextView.setText(title)
}
fun addAction () {
layout.setOnClickListener(object : View.OnClickListener {
override fun onClick(v: View?) {
isChecked = !isChecked
applyUIChanges()
}
})
}
}
and this is the xml
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/xml_square_checkbox_unselected">
<ImageView
android:id="#+id/checkImageView"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="#drawable/ic_ckeck"
android:tint="#color/colorPrimary"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="4dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"/>
<ImageView
android:id="#+id/iconImageView"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_centerHorizontal="true"
android:src="#drawable/ic_placeholder_squre" app:layout_constraintTop_toBottomOf="#+id/checkImageView"
app:layout_constraintBottom_toTopOf="#+id/titleTextView"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="8dp"
android:layout_marginRight="8dp" app:layout_constraintStart_toStartOf="parent"
android:layout_marginLeft="8dp" android:layout_marginStart="8dp"/>
<TextView
android:id="#+id/titleTextView"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_below="#id/iconImageView"
android:ellipsize="end"
android:gravity="center"
android:lines="2"
android:text="#string/text"
android:maxLines="2"
android:textColor="#android:color/black"
android:textSize="12sp"
android:layout_marginBottom="4dp"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/iconImageView"
app:layout_constraintEnd_toEndOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</merge>
and now when i try to use my custom view in my MVVM like this
<com.playground.components.SquareCheckBox
android:id="#+id/inAppMessageCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:isChecked="#{viewModel.inAppEnabled}"
app:iconImage="#drawable/ic_allow_inapp"
app:title="#string/post_listing_settings_in_app_message"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="#+id/voipCheckBox" android:layout_marginStart="8dp"
android:layout_marginEnd="8dp">
it gives me the following error
****/ data binding error ****msg:Cannot find the setter for attribute 'app:isChecked' with parameter type boolean on com.playground.components.SquareCheckBox. file:/Volumes/Data/Work/Amira_Playground/Playground/app/src/main/res/layout/recycler_view_basic_information_settings_item.xml loc:20:33 - 20:54 ****\ data binding error ****
can anyone please advice ?
Seems like it should work, but maybe there's a problem with setter's name/parameter resolving. The docs state that:
For an attribute named example, the library automatically tries to
find the method setExample(arg) that accepts compatible types as the
argument. The namespace of the attribute isn't considered, only the
attribute name and type are used when searching for a method.
You can work this issue around easily with a custom binding adapter. See: https://developer.android.com/topic/libraries/data-binding/binding-adapters
Like this:
#BindingAdapter("isChecked")
fun setIsChecked(view: SquareCheckBox, checked: Boolean) {
view.setChecked(checked)
}
I'm trying to hide part of my view in recycler when user toggles switch.
But when i toggle switch, sometimes it behaves in a strange way and hides only part of my view. It happens every 4 switch clicks (show-hide-show-hide), and i can't manage to solve this bug. Any advices what am i doing wrong?
There are screenshots of properly displayed view and awkwardly hidden view. As you can see, at the second screenshot seekbar with 2 image views is not fully hidden.
UPDATED: The problem is solved. Problem was in include tag. It somehow works wrong, the same layout in item file works fine.
Here is code for hiding logic:
itemView.light_switch.setOnCheckedChangeListener { _, isChecked ->
itemView.brightness.visibility = if (isChecked) View.VISIBLE else View.GONE
lightCallback(lamp, isChecked)
}
And here is my layout (recycler item):
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:background="#1a1a1a">
<ImageView
android:id="#+id/light_icon_image_view"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/prod_foot" />
<TextView
android:id="#+id/light_name_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginStart="8dp"
android:fontFamily="sans-serif-medium"
android:textColor="#ffffff"
android:textSize="16sp"
android:textStyle="normal"
app:layout_constraintBottom_toBottomOf="#+id/light_icon_image_view"
app:layout_constraintStart_toEndOf="#+id/light_icon_image_view"
app:layout_constraintTop_toTopOf="#+id/light_icon_image_view"
tools:text="Floodlight 24 368 (01)" />
<TextView
android:id="#+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:text="No group"
android:textColor="#7fffffff"
android:textSize="14sp"
android:textStyle="normal"
app:layout_constraintStart_toStartOf="#+id/light_name_text_view"
app:layout_constraintTop_toBottomOf="#+id/light_name_text_view" />
<android.support.v7.widget.SwitchCompat
android:id="#+id/light_switch"
style="#style/SwitchCompatStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="#+id/light_icon_image_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/light_icon_image_view"
app:thumbTint="#android:color/white" />
<include
android:id="#+id/brightness"
layout="#layout/brightness_seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/light_icon_image_view">
</include>
<ImageView
android:id="#+id/light_gradient_circle"
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_marginTop="40dp"
app:layout_constraintStart_toStartOf="#+id/light_icon_image_view"
app:layout_constraintTop_toTopOf="#+id/light_icon_image_view"
app:srcCompat="#drawable/badge_color_wheel_active_block" />
</android.support.constraint.ConstraintLayout>
Include layout is provided below (seekbar with 2 images):
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="#1a1a1a"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageView"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginStart="16dp"
app:layout_constraintBottom_toBottomOf="#+id/seekbar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/seekbar"
app:srcCompat="#drawable/ic_dim_min" />
<SeekBar
android:id="#+id/seekbar"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="11dp"
android:layout_marginStart="11dp"
android:layout_marginTop="8dp"
android:max="255"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/imageView2"
app:layout_constraintStart_toEndOf="#+id/imageView"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
app:layout_constraintBottom_toBottomOf="#+id/seekbar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/seekbar"
app:srcCompat="#drawable/ic_dim_max" />
</android.support.constraint.ConstraintLayout>
UPDATED: Adapter full code
class IndividualLightsAdapter(private val context: Context,
private val data: MutableList<Lamp>,
private val lightCallback: (Lamp, Boolean) -> Unit,
private val lightBrightnessCallback: (lamp: Lamp, brightness: Int) -> Unit)
: RecyclerView.Adapter<IndividualLightsAdapter.LightViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LightViewHolder {
val inflater = LayoutInflater.from(parent.context)
val view = inflater.inflate(R.layout.light_item_new, parent, false)
return LightViewHolder(view)
}
override fun getItemCount(): Int = data.size
override fun onBindViewHolder(holder: LightViewHolder, position: Int) {
holder.bind(position)
}
inner class LightViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bind(position: Int) {
val lamp = data[position]
itemView.light_icon_image_view.setImageResource(lamp.imageId)
itemView.light_name_text_view.text = lamp.customName
itemView.light_gradient_circle.visibility = if (lamp is SmartLamp) View.VISIBLE else View.INVISIBLE
itemView.light_switch.isChecked = lamp.isTurnedOn
itemView.light_switch.setOnCheckedChangeListener { _, isChecked ->
itemView.brightness.visibility = if (isChecked) View.VISIBLE else View.GONE
lightCallback(lamp, isChecked)
}
setSeekBar()
itemView.seekbar.progress = lamp.brightness
itemView.seekbar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
lightBrightnessCallback(lamp, progress)
}
override fun onStartTrackingTouch(seekBar: SeekBar) {
}
override fun onStopTrackingTouch(seekBar: SeekBar) {
}
})
}
private fun setSeekBar() {
val gradient = GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,
intArrayOf(ContextCompat.getColor(context, R.color.grad_start), (ContextCompat.getColor(context, R.color.grad_end))))
gradient.cornerRadius = context.resources.getDimension(R.dimen.corner_radius_outer)
val progressLayer = ClipDrawable(gradient, Gravity.START, ClipDrawable.HORIZONTAL)
val background = GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, intArrayOf(Color.BLACK, Color.BLACK))
background.cornerRadius = context.resources.getDimension(R.dimen.corner_radius_inner)
// TODO Calculate padding dynamically
val backgroundLayer = InsetDrawable(background,
context.resources.getDimension(R.dimen.padding_inset_left).toInt(),
context.resources.getDimension(R.dimen.padding_inset_top).toInt(),
context.resources.getDimension(R.dimen.padding_inset_right).toInt(),
context.resources.getDimension(R.dimen.padding_inset_bottom).toInt())
itemView.seekbar.thumb.setTint((ContextCompat.getColor(context, R.color.color_thumb)))
itemView.seekbar.progressDrawable = LayerDrawable(arrayOf<Drawable>(backgroundLayer, progressLayer))
}
}
}
You shouldn't hide the view that is an item of recyclerView.
It doesn't work properly because of its recycling mechanism.
You just need to remove/add the item to be able to do the same effect.
you should has the below methods on your RecyclerView adapter
private void deleteItem(int position) {
if (position != RecyclerView.NO_POSITION) {
myList.remove(position);
notifyItemRemoved(position);
}
}
private void addItem(int position, MyModel model) {
if (position != RecyclerView.NO_POSITION) {
myList.add(position, model);
notifyItemInserted(position);
}
}