Created
March 27, 2019 11:13
-
-
Save Frederikos/8736781c9cb594a459b4091493026a1d 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
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