36.5 Working with the Binding Class
The next step is to modify the code within the MainFragment.java file to inflate the data binding. This is best achieved by rewriting the onCreateView() method:
.
.
import androidx.databinding.DataBindingUtil;
.
.
public class MainFragment extends Fragment {
.
.
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
binding = DataBindingUtil.inflate(
inflater, R.layout.main_fragment, container, false);
binding.setLifecycleOwner(this);
...