Пожалуйста, внимательно прочитайте мой вопрос
Я учусь Activity
LifeCycle
. У меня только один EditText
и TextView
в моем XML макете с определенным id
. Когда я поворачиваю экран, кажется, ничего не меняется, потому что вращение не влияет на EditText
. Но когда я удаляю id
из EditText
в XML
и поворачивал экран, влияние поворота начинается, и текст в editText
удалялся из-за поворота. Меня смущает связь EditText
с его идентификатором.
Я попытался объяснить проблему ниже в столбцах:
Объяснение ниже названий столбцов
- Наличие идентификатора: есть ли у EditText идентификатор?
- Вращение: телефон повернулся или нет
- EditText: Что происходит с EditText после поворота.
.
Having Id
---------------- Rotation
--------------- EditText
Yes Rotated Does not change
No Rotated Yes, Text Removed from editText
MainActivity.java
пусто и main_activity.xml
код указан ниже:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter here"
android:inputType="textPersonName"
android:textSize="26sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.371" />
<TextView
android:id="@+id/textView2"
android:layout_width="85dp"
android:layout_height="25dp"
android:layout_marginTop="88dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
![enter image description here](https://i.stack.imgur.com/8bcPA.png)
![enter image description here](https://i.stack.imgur.com/iPzGx.png)
Извините за использование плохих снимков Engli sh и высокого разрешения, поскольку у меня нет других способов. С наилучшими пожеланиями