应该在我的代码中启动用户=新用户吗?

时间:2019-06-16 07:35:03

标签: android-databinding

我必须在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);  
     } 

0 个答案:

没有答案