我有一个列表视图,其高度宽度都是"匹配父母"使用适配器填充并使用" position"我在getview中得到的是正确的,但viewholder.image.click事件总是根据可见区域给出位置。就像我将listview高度更改为某个静态dp然后可见区域增加到4个元素0,1,2,3之后它再次显示0,1,2,3应该是5,6 ......
每次创建convertView时都会解决此问题,这实际上是一种错误的方法。
public override View GetView(int position, View convertView, ViewGroup parent)
{
MyDealViewHolder viewHolder = null;
View rowView = convertView;
Toast.MakeText (baseActivity, string.Format (position.ToString ()), ToastLength.Short).Show ();
if (rowView == null)
{
rowView = baseActivity.LayoutInflater.Inflate(Resource.Layout.DealListItem, parent, false);
viewHolder = new MyDealViewHolder();
viewHolder.LikeImage= rowView.FindViewById<ImageView>(Resource.Id.imgDealImage);
viewHolder.LikeImage.Click += delegate(object sender, EventArgs e) {
Toast.MakeText (baseActivity, string.Format (position.ToString ()), ToastLength.Short).Show ();
viewHolder.LikeImage.SetImageResource (Resource.Drawable.heart_red_icon);
};
rowView.Tag = viewHolder;
}
else
{
viewHolder= (MyDealViewHolder)rowView.Tag;
}
return rowView;
}
这里两个吐司给出了不同的位置。第一个是正确的,第二个是listview的可见区域
由于