Duplicate value in CustomEditText when change theme or language

This is the custom edittext
part of my code:

class CustomTextInput : FrameLayout {
    private var helperText: CharSequence? = null
    private var validator: TextInputValidator? = null
    private lateinit var binding: CustomTextInputBinding

    var isRequired = false

    private val passwordNumber = 1
    private val number = 2

    private var minCharacters = 0
    private var maxCharacters = 0
    private var showError = false

    var text: String
        get() = binding.customInputEditText.text.toString()
        set(value) = binding.customInputEditText.setText(value)

    var hint: String
        get() = binding.customInputLayout.hint.toString()
        set(value) = binding.customInputLayout.setHint(value)

    var errorFocus: Int = 0
        set(value) {
            binding.customInputEditText.error = context.getString(value)
            text = ""
            binding.customInputEditText.requestFocus()
            if (!showError) {
                showError = true; binding.customInputEditText.background =
                    ContextCompat.getDrawable(context, R.drawable.drawable_text_red)
            }
        }

    fun errorNotFocus(clear: Boolean) {
        if (clear) text = ""
        if (!showError) {
            showError = true; binding.customInputEditText.background =
                ContextCompat.getDrawable(context, R.drawable.drawable_text_red)
        }
    }

    constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
        init(attrs)
    }

    constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    ) {
        init(attrs)
    }
}

Leave a Comment