简体   繁体   English

软键盘,编辑文本和方向更改

[英]Softkeyboard, Edit text and the Orientation change

First of all I'm handling the orientation changes from code, I need that app will go through onCreate() only once and therefore in onConfigurationChanged I manually perform initialization when necessary. 首先,我要处理代码的方向更改,我需要该应用程序仅通过onCreate()一次,因此在onConfigurationChanged我在必要时手动执行初始化。

About the problem: 关于问题:

When I hit the EditText activate the SoftKeyboard, and change the orientation after what I write something in new orientation and submit that (ok or just back button) the text wouldn't appear in the EditText, the text that was written after orientation change! 当我按下EditText时,激活SoftKeyboard,并在我以新的方向编写内容后更改方向,然后提交该内容(单击确定或返回按钮),该文本将不会出现在EditText中,即方向更改编写的文本!

I can save the text from EditText before configchange and then resume it, but if I continue typing in the same softkeyboard after changing the orientation, symbols won't show up, I can type but there's nothing appearing on the screen ie in the EditText . 我可以在configchange之前保存来自EditText的文本,然后恢复它,但是如果更改方向后继续在同一软键盘上键入内容,则不会显示符号,我可以键入,但是屏幕上没有任何显示,即在EditText

I think it's because the SoftKeyboard loosing the link between itself and the original EditText when changing the orientation, because I reinitialize the layout and EditText after configchange but do nothing to say about it to SoftKeyboard, in fact, I even don't know if this is possible. 我认为这是因为在更改方向时SoftKeyboard失去了自身与原始EditText之间的链接,因为在configchange之后我重新初始化了布局和EditText,但对SoftKeyboard却无话可说,实际上,我什至不知道这是否是可能的。 I don't know how to make it work, maybe someone had such an issue. 我不知道如何使它起作用,也许有人遇到了这样的问题。

PS Please don't ask me to use TextWatchers - they're not an option. 附言:请不要让我使用TextWatchers-它们不是一种选择。

UPD UPD

I've uploaded the video that shows the problem in act. 我上传了展示实际问题的视频。 https://youtu.be/eoEBjooYNAU https://youtu.be/eoEBjooYNAU

Here's the code of that app: 这是该应用程序的代码:

Manifest 表现

<activity
android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name" >

MainActivity : MainActivity

public class MainActivity extends AppCompatActivity {
EditText txtMain;
private void Init() {
setContentView(R.layout.activity_main);
txtMain = (EditText) findViewById(R.id.txtMain);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Init();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
String txtMainText = txtMain.getText().toString(); //SAVING THE STATE
Init(); //RELOADING RESOURCES AND VARS REFRESHING ACCORDING TO THE NEW LAYOUT
txtMain.setText(txtMainText); //RESTORING THE STATE
}
}

EditText : EditText

<EditText
android:layout_width="fill_parent"
android:layout_height="100dp"
android:id="@+id/txtMain"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true" />

I really need to solve the problem, maybe I've done something stupid or it's some wide-known bug, anyway, I need your help! 我真的需要解决问题,也许我做了一些愚蠢的事情,或者是一些众所周知的错误,无论如何,我需要您的帮助!

UPD Is there really no one to help me?( UPD真的没有人可以帮助我吗?

已通过解决问题的Fragment类,因为它是描述在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM