material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.39k stars 3.08k forks source link

Data Binding Can't Update Text On ExtendedFloatingActionButton Immediately #3226

Open ngminhkhoa opened 1 year ago

ngminhkhoa commented 1 year ago

Description: I used data binding for display text on ExtendedFloatingActionButton , but it didn't update text, then i tried edit text, textview, ... for sure my code didn't wrong. And yes, other view can display data from view model state flow. Data on ExtendedFloatingActionButton just show when I recreated Fragment or Activity

Expected behavior: image

Source code:

Code for data binding on ExtendedFloatingActionButton :

             <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
                android:id="@+id/copyIdRoomBtn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="12dp"
                android:onClick="@{(v)->setClick.onClick(v)}"
                android:text="@{mainVM.saveCurrentRoomClicked.data != null ? @string/id_room(mainVM.saveCurrentRoomClicked.data._idRoom) : @string/empty_string}"
                app:elevation="0dp"
                app:icon="@drawable/ic_copy" />

Minimal sample app repro:

Android API version: Min is 26 and Max is 33

Material Library version: 1.9.0-alpha01

Device: Poco x3 Pro

p1nh3iro commented 1 month ago

Any updated on this? @imhappi I'm having this exact same bug of not being able to set it programmatically. An workaround is to setup in the style/xml first and then it's possible to change the value by code.