forked from liangfeidotme/MasteringAndroidDataBinding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewStubActivity.java
42 lines (34 loc) · 1.37 KB
/
ViewStubActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.liangfeizc.databinding.sample.viewstub;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.view.View;
import android.view.ViewStub;
import com.liangfeizc.databinding.R;
import com.liangfeizc.databinding.sample.BaseActivity;
import com.liangfeizc.databinding.databinding.ActivityViewStubBinding;
import com.liangfeizc.databinding.databinding.ViewStubBinding;
import com.liangfeizc.databinding.model.User;
public class ViewStubActivity extends BaseActivity {
private ActivityViewStubBinding mBinding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_view_stub);
mBinding.viewStub.setOnInflateListener(new ViewStub.OnInflateListener() {
@Override
public void onInflate(ViewStub stub, View inflated) {
ViewStubBinding binding = DataBindingUtil.bind(inflated);
User user = new User("liang", "fei");
binding.setUser(user);
}
});
}
/**
* Don't panic for red error reporting. Just ignore it and run the app. Surprise never ends.
*/
public void inflateViewStub(View view) {
if (!mBinding.viewStub.isInflated()) {
mBinding.viewStub.getViewStub().inflate();
}
}
}