Skip to content

Instantly share code, notes, and snippets.

@hieuwu
Last active January 24, 2022 09:35
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 hieuwu/8c7e58d9ea67e6bb2870052076d8fa7f to your computer and use it in GitHub Desktop.
Save hieuwu/8c7e58d9ea67e6bb2870052076d8fa7f to your computer and use it in GitHub Desktop.
Customized fluent binding with adapter, view holder for MvxRecyclerView
public class PersonItemAdapter : MvxRecyclerAdapter
{
public PersonItemAdapter(IMvxAndroidBindingContext bindingContext)
: base(bindingContext)
{
}
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
{
var itemBindingContext = new MvxAndroidBindingContext(parent.Context, BindingContext.LayoutInflaterHolder);
var view = InflateViewForHolder(parent, viewType, itemBindingContext);
return new PersonItemViewHolder(view, itemBindingContext);
}
}
private class PersonItemViewHolder : MvxRecyclerViewHolder
{
public PersonItemViewHolder(View itemView, IMvxAndroidBindingContext context)
: base(itemView, context)
{
_nameTextView = itemView.FindViewById<TextView>(Resource.Id.NameTextView);
this.DelayBind(() =>
{
var set = this.CreateBindingSet<PersonItemViewHolder, Person>();
set.Bind(_nameTextView).For(v => v.Text).To(vm => vm.Name).OneWay();
set.Apply();
});
}
private TextView _nameTextView;
}
//Usage in UI Controller:
//_personRecyclerview.Adapter = new AddOnsGroupItemAdapter((IMvxAndroidBindingContext) BindingContext);
//set.Bind(_personRecyclerview).For(v => v.ItemsSource).To(vm => vm.AddOnsGroups).OneWay();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment