I tried to move the edittext focus to one to another (next) when selecting the autofill (suggestions from top of the keyboard). But it is not moving properly.
The approach I tried is mentioned below.
@RequiresApi(Build.VERSION_CODES.O)
private fun setOnAutofillCompleteListener(currentEditText: EditText, nextEditText: EditText) {
currentEditText.setOnFocusChangeListener { v, hasFocus ->
autofillManager.let {
if(!hasFocus) return@setOnFocusChangeListener
autofillManager.registerCallback(object : AutofillManager.AutofillCallback() {
override fun onAutofillEvent(view: View, event: Int) {
if (event == EVENT_INPUT_UNAVAILABLE || event == EVENT_INPUT_HIDDEN) {
nextEditText.requestFocus()
}
}
})
}
}
}
In onCreate of the Activity called the below method
@RequiresApi(Build.VERSION_CODES.O)
private fun registerAutoCompleteListener() {
setOnAutofillCompleteListener(binding.firstName,binding.lastName)
setOnAutofillCompleteListener(binding.lastName,binding.emailAddress)
setOnAutofillCompleteListener(binding.emailAddress,binding.phoneNumber)
setOnAutofillCompleteListener(binding.phoneNumber,binding.password)
setOnAutofillCompleteListener(binding.password,binding.passwordConfirmPassword)
}
Initialized the AutofillManager system service like lateinit property
autofillManager = getSystemService(AutofillManager::class.java)
For example, on selecting the (autofill) suggestion (Firstname Lastname), the first and second edittext should be filled and the focus move to next email address edittext.