Home > Enterprise >  How to get Call Back in another class when text size 4 from TextWatcher
How to get Call Back in another class when text size 4 from TextWatcher

Time:11-12

This is my GenericTextEnterPin Class

     class GenericTextEnterPinPassword (private val view: View, private val editText: ArrayList<EditText>) : TextWatcher {
        
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
            }
        
            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
            }
        
            override fun afterTextChanged(s: Editable?) {
                val string = s.toString()
                when (view.id) {
                    R.id.otp_edit_box5 -> {
                        if (string.length == 1) editText[1].requestFocus()
                    }
                    R.id.otp_edit_box6 -> {
        
                        if (string.length == 1) editText[2].requestFocus() else if (string.isEmpty()) editText[0].requestFocus()
                    }
                    R.id.otp_edit_box7 -> {
                        if (string.length == 1) editText[3].requestFocus() else if (string.isEmpty()) editText[1].requestFocus()
                    }
                    R.id.otp_edit_box8 -> {
                        if (string.isEmpty()) editText[2].requestFocus()
// here we are getting 4 size i want sethere and want to get callback in another class
        
                    }
        
                }
            }
        
        }

i want to getCall Back in my widget class where we are displaying some other view but i am not getting how to get call back in another class below is my class where i want to call back .

class AppLockWidgetImpl @Inject constructor(
    private val context: Context,
    override val onClicked: SingleLiveData<CallToAction>
) : AppLockWidget {
}

enter image description here

CodePudding user response:

You can pass your callback as a lambda function to GenericTextEnterPinPassword.

class GenericTextEnterPinPassword (
    private val view: View, 
    private val editText: ArrayList<EditText>,
    private val callback: () -> Unit
): TextWatcher {
    // ...
    R.id.otp_edit_box8 -> {
        if (string.isEmpty()) editText[2].requestFocus()
        callback()    
    }
    // ...
}

Usage:

val textWatcher = GenericTextConfirmPassword(otp_edit_box11, edit) {
    // Whatever you wish to do upon callback
}
otp_edit_box11.addTextChangedListener(textWatcher)
  • Related