0

I was working on an android wallpaper app in visual studio and got this error mentioned above. I included Gallery and some ImageAdapter code from xamarin website here is the link https://developer.xamarin.com/guides/android/user_interface/gallery/. when i finally compile, It says Gallary is obsolete in my mainactivity.cs file.

 namespace wallpaperApp
 {
   [Activity(Label = "wallpaperApp", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);

        Gallery gallery = (Gallery)FindViewById<Gallery>(Resource.Id.gallery);

        gallery.Adapter = new ImageAdapter(this);

        gallery.ItemClick += delegate (object sender, Android.Widget.AdapterView.ItemClickEventArgs args) {
            Toast.MakeText(this, args.Position.ToString(), ToastLength.Short).Show();
        };
    }
}

}

Keb_Tse
  • 37
  • 6
  • 1
    Possible duplicate of ["The type Gallery is deprecated", Whats the best alternative?](http://stackoverflow.com/questions/11868503/the-type-gallery-is-deprecated-whats-the-best-alternative) – SushiHangover Oct 20 '16 at 03:47
  • Or: http://stackoverflow.com/questions/15833889/options-for-replacing-the-deprecated-gallery – SushiHangover Oct 20 '16 at 03:48
  • Besides me being new to c# android programming, the two sources you listed are in java. I am looking for c# code. – Keb_Tse Oct 20 '16 at 04:18
  • Converting from java to C# is fairly easy, take it line by line, the Java APIs that you are calling with C# are the same... and XML-based Layouts used are identical... – SushiHangover Oct 20 '16 at 04:22
  • ok, I used ecogallery and went through the process and come across this "Include 'EcoGallery' android library to your project. (Eclipse project: properties -> Android -> Library - Add)", how do i do that in visual studio? do i download the files from github and add them in reference folder? – Keb_Tse Oct 20 '16 at 04:35

1 Answers1

0

The Gallery widget in Android is now obsolete and should be replaced with something else. Some possible solutions can be found on the Xamarin forums:

Working with multiple images/bitmap in Xamarin.Android (and, actually, in Android in general) is quite tricky. I'd suggest you to use on of the image downloaders 3rd parties such as Universal Image Loader, Glide, Picasso and so on. Also take a look at https://github.com/rdio/tangoandcache it works good with xamarin's GC and utilizes Bitmap Reuse.

https://forums.xamarin.com/discussion/45567/gallery-imageview-explodes-memory

Adrian Sanguineti
  • 2,252
  • 1
  • 23
  • 27