I have following code inside GetView method of my Custom adapter:
public override View GetView(int position, View convertView, ViewGroup parent)
{
var view = convertView ?? activity.LayoutInflater.Inflate(
Resource.Layout.ScannedTuListItem, parent, false);
var scannedTu = view.FindViewById<TextView>(Resource.Id.scannedTu);
var tuTxt = activity.Resources.GetString(Resource.String.tu);
var custTxt = activity.Resources.GetString(Resource.String.customer);
var orderTxt = activity.Resources.GetString(Resource.String.order);
var targetBinTxt = activity.Resources.GetString(Resource.String.targetBin);
scannedTu.Text =
$"{tuTxt} {tus[position].No}" +
$"\n{custTxt} {tus[position].Customer} / {orderTxt} {tus[position].Order}" +
(string.IsNullOrEmpty(tus[position].TargetBin) ?
string.Empty : $"\n{targetBinTxt} {tus[position].TargetBin}");
if (tus[position].AtPackingStation && !tus[position].Ready)
{
scannedTu.SetBackgroundColor(Color.Yellow);
scannedTu.SetTextColor(Color.Black);
}
else if (tus[position].AtPackingStation && tus[position].Ready || tus[position].ScanOk == true)
{
scannedTu.SetBackgroundColor(Color.Green);
scannedTu.SetTextColor(Color.Black);
}
else if (tus[position].ScanOk == false)
{
scannedTu.SetBackgroundColor(Color.Red);
scannedTu.SetTextColor(Color.Black);
}
return view;
}
When I change Property ScanOK
and Ready
to True
, say, for the first 3 items in the list, it automatically sets the background color of items outside the screen also to Green.
How do I make it color only the first 3 items without affecting items off the screen?