While working with ViewBinding I come across few not documented cases.
First: How to get binding for included generic view layout parts, main binding see only items
Your first question, that is working with an included layout using ViewBinding can be solved so easily.
Here is a sample main_fragment.xml file
And MainFragment.java can be like this
public class MeaningFragment extends Fragment {
private MainFragmentBinding binding;
private ToolbarBinding toolbarBinding;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
binding = MainFragmentBinding.inflate(inflater, container, false);
toolbarBinding = binding.toolbar;
return binding.getRoot();
}
@Override
public void onDestroy() {
super.onDestroy();
toolbarBinding = null;
binding = null;
}
}
Now, you have two bindings. one of them is the default and the next one is from the included layout.