I want to download Images and place them in a grid, But the images don't show up and every +- 1 second, a new thread gets started ?! Also getview is called multiple times with position 0, which i also don't understand.
I'm using Xamarin
public override View GetView(int position, View convertView, ViewGroup parent)
{
View view= convertView;
ViewHolder holder;
if (view == null)
{ // if it's not recycled, initialize some attributes
holder = new ViewHolder();
view = mContext.LayoutInflater.Inflate (Resource.Layout.teamMemberLayout, null);
holder.Image = view.FindViewById<ImageView>(Resource.Id.teamIv);
holder.Name = view.FindViewById<TextView>(Resource.Id.nameTv);
holder.Name.SetTypeface (MainModel.Instance.RegularFont,TypefaceStyle.Normal);
view.Tag = holder;
}
else //recycled view:
{
holder = (ViewHolder)view.Tag;
}
holder.Name.Text=_teamMembers[position].fName;
holder.SetImage (_teamMembers[position],(int)ConvertDpToPix(72),(int)ConvertDpToPix(72));
return view;
}
public float ConvertDpToPix(float dp)
{
return dp * mContext.Resources.DisplayMetrics.Density;
}
}
class ViewHolder : Java.Lang.Object
{
public ImageView Image { get; set; }
public TextView Name { get; set; }
public async void SetImage(UserVO user, int width,int height)
{
Bitmap profileImg = await MainModel.Instance.getProfileImage (user.Profilepicture,width,height);
Image.SetImageBitmap (profileImg);
}
}
Aucun commentaire:
Enregistrer un commentaire