Questions tagged [android-viewbinding]

View binding is a feature that allows you to more easily write code that interacts with views. Once view binding is enabled in a module, it generates a binding class for each XML layout file present in that module. An instance of a binding class contains direct references to all views that have an ID in the corresponding layout. In most cases, view binding replaces findViewById.

View binding is a feature that allows you to more easily write code that interacts with views. Once view binding is enabled in a module, it generates a binding class for each XML layout file present in that module.

An instance of a binding class contains direct references to all views that have an ID in the corresponding layout.

In most cases, view binding replaces findViewById.

You can see this link for more.

482 questions
24
votes
4 answers

How to make BaseFragment with View Binding

My BaseFragment: abstract class BaseFragment : Fragment() { protected abstract val viewModel: ViewModel private var _binding: Binding? = null protected val binding get() = _binding!! …
23
votes
2 answers

How can I access views from layout containing merge tag is included in another layout?

I use Android Studio 3.6-RC1 and build tools version 3.6.0-rc01 and encountered an issue with ViewBinding feature: I have activity_test.xml file with the following markup:
20
votes
4 answers

How to use View Binding in Custom Dialog box layout?

I am having trouble in implementing view binding in a Custom Dialog Layout. Is it possible? private fun showCustomDialog(title: String) { val dialog = Dialog(activity) dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) …
user15460872
19
votes
3 answers

How to use abstraction with ViewBinding with base activity?

I was making a base class so that all bindings for child will be set in base I have done till this abstract class BaseActivity2 : AppCompatActivity() { private var viewBinding: B? = null private var…
19
votes
3 answers

Android ViewBinding with CustomView

I'd like to use try out the ViewBinding with custom view, for example: MainActivity <=> layout_main.xml MyCustomView <=> layout_my_custom_view.xml layout_main.xml
Z.J Hung
  • 475
  • 1
  • 5
  • 12
17
votes
2 answers

Android View Binding - Clear Binding in Fragment Lifecycle

Why is it important to clear the binding in onDestroyView when implementing Android View Binding in a Fragment? As the documentation shows, Use view binding in fragments, and the Android Architecture Components sample, the binding is initiated in…
15
votes
0 answers

In Android Studio the action "Find Usages" by View ID in XML layout doesn't work with Android View Binding

The View Binding in Android is heavily advocated as a better replacement for findViewById() and even Kotlin extensions, but for some reason the most basic functionality as searching usages of a View by its ID in Layout Editor in Android studio…
Alex Wih
  • 1,015
  • 2
  • 11
  • 24
15
votes
13 answers

Android Studio is giving errors and warnings after enabling view binding. How to fix?

I am getting errors after i enabled view binding in my project. I have tried resyncing the project, invalidating cache. My app gradle file: apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin:…
Wizard28
  • 355
  • 1
  • 3
  • 12
15
votes
0 answers

View Binding: Is there a way to generically inflate a layout given a layout id?

With data binding, we have a DataBindingUtil class which has an inflate method that can handle any layout id: binding = DataBindingUtil.inflate(inflater, layoutId, parent, false) With view binding, there doesn't appear to be a…
SilentByte
  • 1,098
  • 1
  • 10
  • 21
14
votes
2 answers

How to use with view binding?

I can't get layouts with merge root tag to work with view binding. Is it possible? include_layout.xml:
jeff
  • 6,299
  • 1
  • 15
  • 18
13
votes
1 answer

ViewBinding - Different Flavor Layout Resource

I have a flavor that contains the same layout resource that is in my main source set. This is so it overrides the main one with the flavor specific one. I have done this in many places and it works fine until I introduced ViewBinding. For accuracy,…
13
votes
1 answer

How to Ignore view component(s) that I do not want to create bindings in Android view Binding library?

I am exploring new Android View Binding library. In my layout XML file, some views that I don't want to include in my binding class. Does there any attribute or mechanism exist that exclude views into generated Binding class?
pRaNaY
  • 24,642
  • 24
  • 96
  • 146
11
votes
1 answer

Quick fragment switching view binding null

I have 2 fragments in a tab layout, switching between them quickly causes the views to be returned as null, using ViewBinding. Is this because of the delay to build the FragmentXBinding class? Usage…
10
votes
3 answers

How to inflate a ViewStub using ViewBinding in Android

As Kotlin Synthetics is deprecated, we are migrating to ViewBinding. I have tried a lot of googling and reading documentation on ViewStub, ViewBinding and have implemented ViewBinding for Fragments Activities, include, merge tags however I could not…
10
votes
2 answers

ViewBinding - How to set visibility for include layout in ViewBinding?

I use an include layout and I need to change it's visibility: and layout_select_provinces is sth like this:
Parisa Baastani
  • 1,713
  • 14
  • 31
1
2
3
32 33