-
-
Save stfalconaleks/13724f8ace8b39434a2fcc1d2d64801a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private AppCompatActivity binding; | |
private ActivityViewModel viewModel; | |
public abstract ActivityViewModel onCreate(); | |
public abstract @IdRes int getVariable(); | |
public abstract @LayoutRes int getLayoutId(); | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
bind(); | |
} | |
public void bind() { | |
binding = DataBindingUtil.setContentView(this, getLayoutId()); | |
this.viewModel = viewModel == null ? onCreate() : viewModel; | |
binding.setVariable(getVariable(), viewModel); | |
binding.executePendingBindings(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment