0
我正嘗試在GridView中將圖像綁定在Fragment中。該片段正在加載,但它是空白的。我在ImageAdapeter的GetView方法上放置了斷點,但它沒有觸及斷點。這是片段是空白的原因嗎?Xamarin Android - 使用ImageAdapter在片段中將圖像綁定到GridView
這裏是我的代碼
片段代碼:
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
ViewGroup root = (ViewGroup)inflater.Inflate(Resource.Layout.profilefragmentlayout, null);
var PhotoGridView = root.FindViewById<GridView>(Resource.Id.PhotoGridView);
PhotoGridView.Adapter = new ImageAdapter(root.Context);
return root;
}
ImageAdapter代碼
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(50, 50);
imageView.SetScaleType(ImageView.ScaleType.CenterCrop);
imageView.SetPadding(5, 5, 5, 5);
}
else
{
imageView = (ImageView)convertView;
}
imageView.SetImageResource(imageIds[position]);
return imageView;
}
int[] imageIds = {
Resource.Drawable.WP1, Resource.Drawable.WP2,
Resource.Drawable.WP3, Resource.Drawable.WP4,
Resource.Drawable.WP5, Resource.Drawable.WP6,
Resource.Drawable.WP7, Resource.Drawable.WP8,
Resource.Drawable.WP9, Resource.Drawable.WP10,
Resource.Drawable.WP11, Resource.Drawable.WP12,
};
}
}
請讓我什麼,我很想念它停下來綁定圖像在片段中的gridview。
能有人幫助呢? – user3509981