我必须在MainActivity中启动User类吗?喜欢User user = new User
?我有用户作为set方法的参数吗?谢谢
<layout xmlns.androide•http://schemas.android.com/apk/res/androir>
<data>
<variable
name= "user"
type="com.example.model.User" />
</data>
<RelativeLayout>
<TextView android.text="@{"Hello, " + user.name}"
</RelativeLayout>
</layout> `enter code here`
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedlnstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
// user is name = "user" of in the variable of <data>
binding.setUser(user);
}