Skip to content

Instantly share code, notes, and snippets.

@Frederikos
Created March 27, 2019 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Frederikos/8736781c9cb594a459b4091493026a1d to your computer and use it in GitHub Desktop.
Save Frederikos/8736781c9cb594a459b4091493026a1d to your computer and use it in GitHub Desktop.
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;
}
@Override
public BindingHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new BindingHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_place, parent, false));
}
@Override
public void onBindViewHolder(BindingHolder holder, int position) {
ItemPlaceBinding placeBinding = holder.getBinding();
placeBinding.setViewModel(new PlaceItemViewModel(activity, places.get(position)));
holder.getBinding().executePendingBindings();
}
public static class BindingHolder extends RecyclerView.ViewHolder {
private ItemPlaceBinding binding;
public BindingHolder(View rowView) {
super(rowView);
binding = DataBindingUtil.bind(rowView);
}
public ItemPlaceBinding getBinding() {
return binding;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment