我有两种布局,根据库存中的产品可用性(可用和缺失)使用。我尝试使用它们但没有成功,所以我创建了一个标准布局并更改包含每个案例设置的Shape。这是最好的方法吗?如何在我的布局应用程序中同时使用它们? Ps .:请记住,ListView不会使用交替颜色(斑马纹),而是根据产品的可用性。
using System;
using Android.App;
using Android.Views;
using Android.Widget;
using ServiceClass.Auvo_WebService;
using Android.Content;
using AppClass_Mobile;
public class AdapterProduct : BaseAdapter
{
private Activity _Activity = null;
private static Product[] _ListOfProduct;
public static User _InstaceOfUser;
public static LayoutInflater _Inflater = null;
private View _View;
public AdapterProduct(Activity activity, Product[] listOfProduct)
{
_Activity = activity;
_ListOfProduct = listOfProduct;
try
{
_Inflater = (LayoutInflater)_Activity.GetSystemService(Context.LayoutInflaterService);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
_View = convertView;
ViewHolderProduct holderProduct;
try
{
if (_View != null)
holderProduct = _View.Tag as ViewHolderProduct;
else
{
_View = _Activity.LayoutInflater.Inflate(Resource.Layout.LayoutGenericProd, null);
holderProduct = CriaHolder(position);
}
PopulaHolder(holderProduct, position);
_View.Tag = holderProduct;
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
return _View;
}
private void PopulaHolder(ViewHolderProduct holderProduct, int position)
{
if (_ListOfProduct[position].ThisProductIsOk)
{
holderProduct.descrProd.SetBackgroundResource(Resource.Layout.ShapeRoundedCornerOut);
holderProduct.descrProd.SetTextColor(Android.Graphics.Color.Black);
}
else
holderProduct.descrProd.SetBackgroundResource(Resource.Layout.ShapeRoundedCornerIn);
holderProduct.descrProd.Text = _ListOfProduct[position].Name;
holderProduct.lastUpDate.Text = _ListOfProduct[position].DataProduct.ToString("HH:mm");
}
private ViewHolderProduct CriaHolder(int position)
{
ViewHolderProduct holderProduct = new ViewHolderProduct();
holderProduct.descrProd = _View.FindViewById<TextView>(Resource.Id.descrProd);
holderProduct.lastUpDate = _View.FindViewById<TextView>(Resource.Id.lastUpDate);
return holderProduct;
}
public override Java.Lang.Object GetItem(int position)
{
return null;
}
public override long GetItemId(int position)
{
return position;
}
public override int Count
{
get { return _ListOfProduct.Length; }
}
public int GetCount()
{
return _ListOfProduct.Length;
}
public void AddItem(Product product, User User)
{
try
{
if (User.SerialNum == _InstaceOfUser.SerialNum)
AddPordInList(product);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
private void AddPordInList(Product product)
{
Array.Resize(ref _ListOfProduct, _ListOfProduct.Length + 1);
_ListOfProduct[GetCount() - 1] = product;
this.NotifyDataSetChanged();
}
private class ViewHolderProduct : Java.Lang.Object
{
public TextView descrProd { get; set; }
public TextView lastUpDate { get; set; }
public ImageView statusProd { get; set; }
}
}