Customized fluent binding with adapter, view holder for MvxRecyclerView
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 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