5

I have created an MvxListView with a custom adapter, but none of the adapter methods are getting called. It is worth mentioning the list is in a fragment. What am I doing wrong?

Adapter:

public class WishlistAdapter : MvxAdapter
{
    public WishlistAdapter(Context context, IMvxAndroidBindingContext bindingContext)
        : base(context, bindingContext)
    {
    }

    protected override View GetBindableView(View convertView, object source, int templateId)
    {
        if (((Wish)source).IsOwner == false)
        {
            if (((Wish)source).IsBought)
            {
                templateId = Resource.Layout.listitem_wishbought;
            }
        }

        return base.GetBindableView(convertView, source, templateId);
    }
}

View:

    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        base.OnCreateView(inflater, container, savedInstanceState);

        var view = this.BindingInflate(Resource.Layout.WishlistView, null);

        var list = view.FindViewById<ListView>(Resource.Id.WishlistView_ListWishes);
        list.Adapter = new WishlistAdapter(Activity, (MvxAndroidBindingContext)BindingContext);

        return view;
    }

ViewModel:

    public ObservableCollection<Wish> Wishes
    {
        get
        {
            return _Wishes;
        }
        set
        {
            _Wishes = value;
            RaisePropertyChanged("Wishes");
        }
    }

FIXED:

    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        base.OnCreateView(inflater, container, savedInstanceState);

        var view = this.BindingInflate(Resource.Layout.WishlistView, null);

        var list = view.FindViewById<**MvxListView**>(Resource.Id.WishlistView_ListWishes);
        list.Adapter = new WishlistAdapter(Activity, (MvxAndroidBindingContext)BindingContext);

        return view;
    }
Martijn00
  • 3,569
  • 3
  • 22
  • 39
Hoffmann
  • 149
  • 12
  • Do your adapter overrides get called in a simple `Activity` based test case? i.e. is this a problem only with the fragment display or in general? Can you repro the behaviour in a simple test case? How are you testing whether or not your overrides are called? – Stuart Nov 14 '13 at 18:00
  • I tried putting the problem to the test in an activity, but the problem was still there. I am using break points to check whether the overrides are called. Any further ideas? :) – Hoffmann Nov 14 '13 at 18:19
  • 1
    Try seeing if you can spot the difference with a sample that does work - maybe https://github.com/MvvmCross/MvvmCross-Tutorials/blob/master/Working%20With%20Collections/Collections.Droid/Views/PolymorphicListItemTypesView.cs ? – Stuart Nov 14 '13 at 18:31
  • 1
    I am an idiot. I casted the List to a ListView instead of an MvxListView. Problem solved. Thanks for the help Stuart, and great work with MVVMCross btw ;) – Hoffmann Nov 14 '13 at 19:28
  • 1
    Excellent - when soverflow allows you, please add an answer to your own question. – Stuart Nov 14 '13 at 19:43

0 Answers0