Please Read My Question Carefully
I am learning Activity
LifeCycle
. I only have one EditText
and a TextView
in my XML layout With certain id
. When I rotate the screen, nothing seems to change because Rotation doesn't affect EditText
. But when I remove the id
of EditText
in XML
and rotated the screen, The Rotation Starts affecting and the text in the editText
removed due to rotation. I am confused about the relation of EditText
with its Id.
I tried to explain the problem below in columns:
Explanation of below Column names
- Having Id: Does EditText has id?
- Rotation : Phone has Rotated or not
- EditText : What happen to EditText After Rotation.
.
Having Id
----------------Rotation
---------------EditText
Yes Rotated Does not change
No Rotated Yes, Text Removed from editText
MainActivity.java
is empty and main_activity.xml
code is below:
<?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>
Sorry for using bad English and High-resolution pictures as I have no other ways. Best Regards