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
9
votes
4 answers

How to use View Binding on BottomSheetDialog

I'm trying to make a BottomSheetDialog inside my MainActivity, but right now I'm using synthetic to bind my views. But now I'm stuck with how to attach ViewBinding to my BottomSheetDialog. Here's what I do, using synthetic. dialog =…
9
votes
4 answers

Where is ViewBinding GeneratedCode

How/Where Can I find the generated code for ViewBinding? whenever I try control+click/control+b to see the declaration, AndroidStudio just opens the XML layout.
8
votes
3 answers

Using ViewBinding on an ArrayAdapter

I'm trying to refactor my app to use ViewBinding. I've gone through all the fragments and activities; however, I have an ArrayAdapter that I'm unsure of the proper convention to use view binding to prevent memory leaks. What is the proper way to use…
user-44651
  • 3,924
  • 6
  • 41
  • 87
8
votes
2 answers

Access view binding in Fragment from Activity

I am upgrading an application to remove all synthetics and use the new ViewBinding feature. So far everything works as long as you are inside of the class/layout you are accessing, but I have synthetic references to layout elements in my Main…
8
votes
3 answers

Viewbinding in Fragment causes KotlinNullPointerException running within lifecycle scoped coroutine

I am setting up my Fragment like suggested in Google docs as such: private var _binding: MyBinding? = null private val binding get() = _binding!! override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,…
A1m
  • 2,897
  • 2
  • 24
  • 39
8
votes
4 answers

ViewBinding - Included Layout Binding Resulting in Unresolved Reference

I am implementing ViewBinding in one of my fragments. This fragment has a layout included like so: ...
StuStirling
  • 15,601
  • 23
  • 93
  • 150
8
votes
1 answer

Android ViewBindings across dynamic features

So happenned that I have a main app module build.gradle dynamicFeatures = [":myFeature"] viewBinding { enabled = true } AdroidManifest.xml package="com.mydomain.testproject" With some common layouts which I'm using across…
Stumi
  • 572
  • 5
  • 8
8
votes
2 answers

How to use fragment with ViewBinding?

I want to create a fragment with ViewBinding but my code not working. I read ViewBinding Documentation but my fragment not show. This is my…
ch65
  • 321
  • 3
  • 8
7
votes
1 answer

Why reference of a view using a binding class is marked with @Nullable?

I have a layout with some TextView and a CardView. Only the reference binding.mycardview returns an object CardView?, but according to docs: Null safety: Since view binding creates direct references to views, there's no risk of a null pointer…
Simone
  • 425
  • 1
  • 6
  • 17
7
votes
2 answers

Should ViewBinding properties in fragments always have a backing non-nullable property?

I've been reading https://developer.android.com/topic/libraries/view-binding and was thinking about how they define their view binding property in a fragment. This is the sample code: private var _binding: ResultProfileBinding? = null // This…
SmallGrammer
  • 893
  • 9
  • 19
7
votes
3 answers

ViewBinding with Java11, AndroidStudio always shows error (but runs without any problem)

I notice that with Java8 there is no problem with viewBinding in AndroidStudio (Arctic Fox). compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } buildFeatures { viewBinding…
hata
  • 11,633
  • 6
  • 46
  • 69
7
votes
2 answers

How to solve 'data binding is not enabled' error while using view binding

I am using view binding and to do so I used the following code. buildFeatures{ viewBinding true } And I got this error: > [databinding] {"msg":"Found \u003clayout\u003e but data binding is not > enabled.\n\nAdd buildFeatures.dataBinding \u003d true…
Akr
  • 117
  • 2
  • 10
7
votes
5 answers

Why using View Binding is changing the layout?

Actual Code: My Main Activity: class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding =…
Wizard28
  • 355
  • 1
  • 3
  • 12
7
votes
4 answers

Navigation with View Binding

I'm trying to replace all findViewById using View Binding. But, I can't change my NavController code line using View Binding. val navController = findNavController(this, R.id.mainHostFragment) to var binding : ActivityMainBinding val navController…
Thaw De Zin
  • 1,409
  • 2
  • 10
  • 18
7
votes
3 answers

Using ViewBinding with multiple layout

Edit - solution When using view binding, a Java binding file is generated for each xml. The problem was that when you modify the xml, it doesn't regenerate the Java files. So, when I added an ID tag to the App_bar_main in activity_main.xml, I was…
Reda Hammoud
  • 333
  • 3
  • 9
1 2
3
32 33