Skip to content Skip to sidebar Skip to footer

Viewbinding- Not Working For Child Layouts

I'm currently updating the source code with the ViewBindings but I'm not getting them to work for child layouts of the other modules which was working previously. I'm on Android St

Solution 1:

Only answers the problem that the included layout is in another module:

For a quick fix if the player_video_controls.xml is not in the same module as player_video_controls.xml, add it to the same module or instead of including it, add the layout itself (which is awful but it works).

But, if you have many instances of this issue I suggest you read this answer and try to enable ViewbBinding in every module of your project that is a direct or indirect dependency of the module with this problem.

Solution 2:

bindig.playerVolumeLayout.btnMute your can access like this

Solution 3:

Instead of :

binding.testPlayerView.findViewById(R.id.btnMute),

In your FragmentBindingProvider.kt:

   binding.testPlayerView.btnMute

Because after you do binding.btnMute? and may be btnMute is null and setOnCheckedChangeListener won't be trigger. If it's not the solution remove your val btnMute: ToggleButton? to val btnMute: ToggleButton and remove binding.btnMute? by binding.btnMute. But nromaaly viewbinding is null safe so you have a value for your button.

Post a Comment for "Viewbinding- Not Working For Child Layouts"