简体   繁体   中英

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.

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!

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 .

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. 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.

UPD

I've uploaded the video that shows the problem in act. 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 :

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
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?(

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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