Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Xamarin.Android upgrade this morning caused regression in ViewPager

$
0
0

This morning I upgraded to the new Xamarin.Android build, and this caused a regression. I have an ImagePagerAdapter which slides photos left and right, which was working beautifully until after this upgrade. Now I can't convert the View collection in InsantiateItem to a ViewPager, even though it IS a ViewPager. Since I can't convert it, I can't add the inflated ImageView to the ViewPager.

The interesting thing is that the View collection parameter is of type android.support.v4.view.ViewPager, whereas the ViewPager type we're trying to convert to is of type Android.Support.V4.View.ViewPager. Notice the casing difference, one is lower-case and the other is capitalized, so they really are of different types now.

So what's the deal? Do I need to downgrade my Xamarin.Android install until this is fixed or is there a new way I should be doing this?

Here is the code.

`public class ImagePagerAdapter : PagerAdapter { private List data; private Context context;

    public ImagePagerAdapter(Context context, List<string> data) {
        this.context = context;
        this.data = data;
    }

    public override Java.Lang.Object InstantiateItem(View collection, int position) {
        // Create new image view
        var uri = data [position];
        var imageView = new ImageView(context);
        var defaultImage = context.Resources.GetDrawable (Resource.Drawable.noimage);
        imageView.SetUrlDrawable (uri, defaultImage);
        // Add image view to pager
        var viewPager = collection as ViewPager;// TODO: This returns null after Xamarin.Android update!
        viewPager.AddView(imageView);
        return imageView;
    }

    public override void DestroyItem(View collection, int position, Java.Lang.Object view) {
        var viewPager = collection as ViewPager;
        viewPager.RemoveView (view as View);
    }

    public override bool IsViewFromObject(View view, Java.Lang.Object obj) {
        return view == obj;
    }

    public override IParcelable SaveState() {
        return null;
    }

    public override void StartUpdate(View arg0) {
    }

    public override void FinishUpdate(View arg0) {
    }

    public override int Count {
        get {
            return data != null ? data.Count : 0;
        }
    }
}`

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>