https://kotlinlang.org logo
#compose
Title
# compose
f

flosch

08/12/2020, 10:07 AM
Hey! assuming I have two (Outlined)TextFields, how can I switch focus from the first to the second after
imeActionPerformed
?
Copy code
Column {
    OutlinedTextField(
        label = { Text("Amount") },
        value = amount,
        onValueChange = { value -> },
        imeAction = ImeAction.Next,
        onImeActionPerformed = { _, controller -> 
            // how do I switch focus to next OutlinedTextField here?
        },
        keyboardType = KeyboardType.Number
    )

    Spacer(modifier = Modifier.height(12.dp))

    OutlinedTextField(
        label = { Text("Reason") },
        value = reason,
        onValueChange = { value -> },
        imeAction = ImeAction.Done,
        onImeActionPerformed = { _, controller -> controller?.hideSoftwareKeyboard() }
    )
}
z

Zach Klippenstein (he/him) [MOD]

08/12/2020, 1:37 PM
I think the focus API is in transition. There's a relatively new FocusRequester API for this I think, but I don't think TextField supports it yet.
f

flosch

08/12/2020, 1:41 PM
thanks! I was actually looking into
FocusRequester
but then thought that it looked too complicated for the good old regular “ImeAction Next-> Focus Next Focusable View” use case. I’ll try to look more into that API then for now
z

Zach Klippenstein (he/him) [MOD]

08/12/2020, 1:50 PM
It does seem pretty complicated, and its interaction with the
focus
modifier seems unintuitive. Hopefully some docs will eventually clear things up.