Problem With Viewbindng In Fragments In Android
I had an Activity and used ViewBinding there without problems. Not I created a similar Fragment and intend to use ViewBinding there too. Unfortunately I get error messages, altough
Solution 1:
First of all, don't use trailing underscore in the layout file name. Remove the trailing underscore from fragment_menu_
A binding class is generated for each layout file. By default, the name of the class is based on the name of the layout file, converting it to Pascal case and adding the Binding suffix to it. The above layout filename is activity_main.xml so the corresponding generated class is
ActivityMainBinding
.
So if the name of your layout file is frargemnt_menu.xml, so the corresponding generated class is FragmentMenuBinding
@OverridepublicViewonCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//Inflate using viewbinding
binding = FragmentMenuBinding.inflate(inflater, container, false);
return binding.getRoot();
}
Post a Comment for "Problem With Viewbindng In Fragments In Android"