Fork us on GitHub

TIP: Don't Put Text Fields in Dialogs

This is a pretty common tip but I can't see a place where this is properly explained
TIP: Don't Put Text Fields in Dialogs

TIP: Don't Put Text Fields in Dialogs

Text input is a very special case. Besides mixing the native and Java code we also need to deal with the appearance of the virtual keyboard which doesn’t act consistently across platforms. This creates many complex edge cases that are just as problematic on native OS platforms as they are in Codename One.

When we show a virtual keyboard there are two main scenarios that can take place:

  • The screen can resize to show only the relevant area

  • Scrolling size can increase to allow us to scroll all the way down

Both of these are problematic in a Dialog. The dialog can’t be properly moved once it is shown. This means that a screen resize can leave the dialog without enough space. Increased scrolling might not be enough since a dialog starts from a cramped position.

This is a problem that is often observed in native Android applications (not as much on iOS) where a field is unreachable when the virtual keyboard is showing.

These issues apply to other UI types where the text field is stuck in a position that doesn’t work well with scrolling or resizing. So you should pay attention to the behavior of the app on resize. A good approach to testing this is rotating a phone simulator which limits the height by a similar ratio. If the field isn’t easily reachable when you rotate the phone you might have a problem with a virtual keyboard too.

Share this Post:

Posted by Shai Almog

Shai is the co-founder of Codename One. He's been a professional programmer for over 25 years. During that time he has worked with dozens of companies including Sun Microsystems.
For more follow Shai on Twitter & github.