Databinding in Fragment

suggest change

Data Model

public class Item {

private String name;

public String getName() { return name; }

public void setName(String name){ = name; }


Layout XML

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="">
       <variable name="item" type="com.example.Item"/>


android:orientation=“vertical” android:layout_width=“match_parent” android:layout_height=“match_parent”>



public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

FragmentTest binding = DataBindingUtil.inflate(inflater, R.layout.fragment_test, container, false); Item item = new Item(); item.setName(“Thomas”); binding.setItem(item); return binding.getRoot();


Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents