using System;
using
Android.App;
using
Android.Content;
using
Android.Runtime;
using
Android.Views;
using
Android.Widget;
using
Android.OS;
namespace
WelcomeGridView
{
[Activity(Label
= "WelcomeGridView", MainLauncher =
true, Icon = "@drawable/icon")]
public class
Activity1 :
Activity
{
protected
override void OnCreate(Bundle
bundle)
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
var PhotoGridView = FindViewById<GridView>(Resource.Id.PhotoGridView);
PhotoGridView.Adapter = new
ImageAdapter(this);
PhotoGridView.ItemClick += delegate(object
sender, ItemEventArgs args)
{
Toast.MakeText(this,
(args.Position+1).ToString(), ToastLength.Short).Show();
};
}
public class
ImageAdapter :
BaseAdapter
{
Context contextcreate;
public ImageAdapter(Context
a)
{
contextcreate
= a;
}
public override
int Count
{
get { return
imageIds.Length; }
}
public override
Java.Lang.Object GetItem(int
position)
{
return null;
}
public override
long GetItemId(int
position)
{
return 0;
}
public override
View GetView(int
position, View convertView,
ViewGroup parent)
{
ImageView imageView;
if (convertView ==
null)
{
imageView
= new ImageView(contextcreate);
imageView.LayoutParameters = new
GridView.LayoutParams(90,
90);
imageView.SetScaleType(ImageView.ScaleType.CenterCrop);
imageView.SetPadding(10, 10, 10, 10);
}
else
{
imageView = (ImageView)convertView;
}
imageView.SetImageResource(imageIds[position]);
return imageView;
}
int[] imageIds = {
Resource.Drawable.mahesh,
Resource.Drawable.dbeniwal321,
Resource.Drawable.kartik,
Resource.Drawable.mgold,
Resource.Drawable.dhananjaycoder,
Resource.Drawable.nandi,
Resource.Drawable.praveen,
Resource.Drawable.suthish,
Resource.Drawable.nipuntomar,
Resource.Drawable.dpatra,
Resource.Drawable.jaganathan,
Resource.Drawable.abhikumarvatsa,
};
}
}
}