I want to change text of TextView which is in inner ConstraintLayout.
When I try binding.lyricViewTitle.text = it.title, binding.lyricViewTitle text is changed(I check with Debug), but lyricViewTitle text is not updated at UI.
When I try binding.lyricView.findViewById<TextView>(R.id.lyric_view_title).text = it.title, text is changed and UI also is updated.
What's the difference? Is there any inner logic in ViewBinding?
// activity_mail.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:id="@+id/constraint_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.media3.ui.PlayerControlView
android:id="@+id/player_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:controller_layout_id="@layout/custom_exo_player_control_view"
app:hide_on_touch="false"
app:repeat_toggle_modes="one"
app:show_shuffle_button="true"
app:show_timeout="0" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/lyric_view"
android:layout_width="0dp"
android:animateLayoutChanges="true"
android:layout_height="0dp"
android:background="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/player_view">
<TextView
android:id="@+id/lyric_view_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:ellipsize="end"
android:maxLines="1"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@id/lyric_view_close"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Love wins all Love wins all Love wins all " />
( ... omit ... )
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
I don't think there's any difference. But, I think
<layout>is needed. I couldn't reproduce nor build without it.Binding class is just an android view mapping class.
binding.lyricView.findViewById<TextView>(R.id.lyric_view_title)andbinding.lyricViewTitleare pointing the same view object.Android view system is hierarchical so
findingViewfinds a view from parent. And it costs a lot. So binding class was introduced in Android.