Skip to content

Instantly share code, notes, and snippets.

View Frederikos's full-sized avatar

Glebov Sergey Frederikos

View GitHub Profile
public class TitleItemViewModel {
public final ObservableField<String> title = new ObservableField<>();
public TitleItemViewModel() {
title.set("Some title");
}
public void titleClicked(View view) {
title.set("Title clicked");
}
<TextView
style="@style/Subtitle"
android:text="@{viewModel.title}"
android:onClick="@{viewModel.titleClicked}"/>
public final ObservableField<Boolean> isDataLoading = new ObservableField<>();
android:visibility="@{viewModel.isDataLoading ? android.view.View.VISIBLE : android.view.View.GONE}"
public final ObservableField<String> countVotes = new ObservableField<>();
public class PlacesAdapter extends RecyclerView.Adapter<PlacesAdapter.BindingHolder> {
private List<PlacesResponseModel.PlaceModel> places;
private Activity activity;
public PlacesAdapter(Activity activity, List<PlaceModel> places) {
this.activity = activity;
this.places = places;
}
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewModel"
type="com.test.sample.viewmodel.PlaceItemViewModel" />
</data>
<LinearLayout
<data>
<variable name="your sample name" type="com.sample.SampleClassName"/>
</data>
public class PlaceItemViewModel {
private Context context;
private PlaceModel placeModel;
public PlaceItemViewModel(Context context, PlaceModel placeModel) {
this.context = context;
this.placeModel = placeModel;
}
private ActivityMainBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
//tvTitle = TextView in layout with id = tv_title
binding.tvTitle.setText("Hello world!");
}