添加运行时视图,以便我可以在 MVVM 中添加该视图数据。
这是代码
FragmentHomeBinding fragmentHomeBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_home, container, false);
FragmentHomeViewModel fragmentHomeViewModel = new FragmentHomeViewModel(getActivity());
fragmentHomeBinding.setViewModel(fragmentHomeViewModel);
/*Adding Dynamic View At run time.*/
View dynamicToFromView = getLayoutInflater()
.inflate(R.layout.dynamic_from_to, fragmentHomeBinding.llDynamicLayoutContainer, false);
fragmentHomeBinding.llDynamicLayoutContainer.addView(dynamicToFromView);
R.layout.dynamic_from_to
是需要在运行时添加到数据的视图。