Android: Add QtEditText to QtWindow in constructor

Of course, createSurface() is called more than once, for example
when coming back from the background, and you cannot add a View
to the layout more than once, since this leads to an uncaught
exception and a crash.

So add the QtEditText once, in the constructor, as is indeed
sensible.

Fixes: QTBUG-122648
Change-Id: I7ef48951cd8a1c99935f5e96c70b6dbf0c745803
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
(cherry picked from commit 211e51b81ec9800161d0a98c6f70c747701035e8)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tinja Paavoseppä 2024-02-22 14:05:11 +02:00 committed by Qt Cherry-pick Bot
parent 46ead3fbef
commit ec9eb9d90b

View File

@ -33,6 +33,8 @@ class QtWindow extends QtLayout implements QtSurfaceInterface {
m_editText = new QtEditText(context, delegate);
setParent(parentWindow);
setFocusableInTouchMode(true);
addView(m_editText, new QtLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
QtNative.runAction(() -> {
m_gestureDetector =
@ -111,8 +113,6 @@ class QtWindow extends QtLayout implements QtSurfaceInterface {
// The surface container of this window will be added as the first of the stack.
// All other views are stacked based on the order they are created.
addView(m_surfaceContainer, 0);
addView(m_editText, new QtLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
});
}