0
사용자 정의 회 전자 어댑터를 만드는 데 문제가 있습니다. 목록에있는 각 국가 항목의 왼쪽에있는 국가 이미지로 국가 선택 도구를 만들려고합니다. 그것은 오류없이 실행되지만 항목을 선택하고 회 전자를 다시 열 때 목록 항목이 위치를 변경하는 이상한 버그가 있습니다.Xamarin 안드로이드 회 전자 어댑터 이상한 버그
class SpinnerAdapter : BaseAdapter, ISpinnerAdapter
{
private string[] data;
private string[] dataValues;
private Context context;
private LayoutInflater inflater;
private bool drawableFlags;
public SpinnerAdapter(Context _context, string[] _data, string[] _dataValues, bool _drawableFlags)
:base()
{
context = _context;
data = _data;
dataValues = _dataValues;
drawableFlags = _drawableFlags;
}
public override int Count => data.Length;
public override Java.Lang.Object GetItem(int position)
{
return data[position];
}
public override long GetItemId(int position)
{
//throw new NotImplementedException();
return (long)position;
}
public string GetItemValue(int position)
{
return data[position];
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
//throw new NotImplementedException();
View view = convertView;
SpinnerAdapterViewHolder holder = null;
if (view != null)
{
holder = view.Tag as SpinnerAdapterViewHolder;
string name = holder.CountryName.Text;
}
if(holder == null)
{
holder = new SpinnerAdapterViewHolder();
var inflater = context.GetSystemService(Context.LayoutInflaterService).JavaCast<LayoutInflater>();
//replace with your item and your holder items
//comment back in
view = inflater.Inflate(Resource.Layout.Spinner_Item_Layout, parent, false);
holder.CountryName = view.FindViewById<TextView>(Resource.Id.SpinnerItem);
holder.CountryName.Text = data[position];
//holder.CountryValue = dataValues[position];
if (drawableFlags)
{
Drawable flag = AppCommon.GetDrawableResourceByName("flag_" + dataValues[position], context);
flag.SetBounds(10, 10, 10, 10);
holder.CountryName.SetCompoundDrawablesWithIntrinsicBounds(flag, null, null, null);
}
view.Tag = holder;
}
return view;
}
}
class SpinnerAdapterViewHolder : Java.Lang.Object
{
public TextView CountryName { get; set; }
public string CountryValue { get; set; }
}