然后创建一个 ViewPager 包含一个框,由一个图像组成并写......每个页面由 4 个框组成。这是我的创建框代码:
namespace ProvaViewPager.Widget.CatalogoBox
{
public class CatalogoBox : RelativeLayout
{
private LayoutInflater _mInflater;
private LinearLayout _mBox;
private void Initialize ()
{
}
public CatalogoBox (IntPtr doNotUse, JniHandleOwnership transfer)
: base(doNotUse, transfer)
{
}
public CatalogoBox (Context context, IAttributeSet attrs)
: base(context, attrs)
{
InternalCtor (context, attrs);
}
public CatalogoBox (Context context, IAttributeSet attrs, int defStyle)
: base(context, attrs, defStyle)
{
InternalCtor (context, attrs);
}
~CatalogoBox ()
{
Dispose (false);
}
private void InternalCtor (Context context, IAttributeSet attrs)
{
_mInflater = (LayoutInflater)context.GetSystemService (Context.LayoutInflaterService);
_mBox = (LinearLayout)_mInflater.Inflate (Resource.Layout.CatalogoBox, null);
AddView (_mBox);
}
}
}
在这里(SwiftView 类:Fragment)我们记得:
public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
TextView TxtCDPAR;
TextView TxtDEPAR;
TextView TxtPrezzo;
TextView TxtPz;
ImageView ImageDisp;
ImageView ImgFreccia;
ImageView ImgIncrementa;
ImageView ImgDecrementa;
ImageView ImageItem;
EditText Quantita;
ImageView ImageProduct;
LinearLayout BoxAddProdotto;
View v = inflater.Inflate (Resource.Layout.PageViewXml, container, false);
if (v != null) {
#region BOX1
var BoxProdotto1 = v.FindViewById<ProvaViewPager.Widget.CatalogoBox.CatalogoBox> (Resource.Id.CatalogoBox1);
TxtCDPAR = BoxProdotto1.FindViewById<TextView> (Resource.Id.CAT_TxtCodiceProdotto);
TxtDEPAR = BoxProdotto1.FindViewById<TextView> (Resource.Id.CAT_DescrProdotto);
ImageView ImagetItem1 = BoxProdotto1.FindViewById<ImageView> (Resource.Id.CAT_ImageProduct) as ImageView;
TxtPz = BoxProdotto1.FindViewById<TextView> (Resource.Id.CAT_NumeroPezzi);
TxtPrezzo = BoxProdotto1.FindViewById<TextView> (Resource.Id.CAT_TxtPrezzo);
BoxAddProdotto = BoxProdotto1.FindViewById<LinearLayout> (Resource.Id.BoxAddProdotto);
ImageDisp = BoxProdotto1.FindViewById<ImageView> (Resource.Id.CAT_ImgDisp);
ImgFreccia = BoxProdotto1.FindViewById<ImageView> (Resource.Id.CAT_ImgFreccia);
ImgIncrementa = BoxProdotto1.FindViewById<ImageView> (Resource.Id.imageIncrementa);
ImgDecrementa = BoxProdotto1.FindViewById<ImageView> (Resource.Id.imageDecrementa);
Quantita = BoxProdotto1.FindViewById<EditText> (Resource.Id.editNumerico);
ImageProduct = BoxProdotto1.FindViewById<ImageView> (Resource.Id.CAT_ImageProduct);
TxtPz.Visibility = ViewStates.Invisible;
ImagetItem1.SetImageResource (Resource.Drawable.imagespiaggia);
#endregion
#region BOX2
var BoxProdotto2 = v.FindViewById<ProvaViewPager.Widget.CatalogoBox.CatalogoBox> (Resource.Id.CatalogoBox2);
TxtCDPAR = BoxProdotto2.FindViewById<TextView> (Resource.Id.CAT_TxtCodiceProdotto);
TxtDEPAR = BoxProdotto2.FindViewById<TextView> (Resource.Id.CAT_DescrProdotto);
ImageItem = BoxProdotto2.FindViewById<ImageView> (Resource.Id.CAT_ImageProduct) as ImageView;
TxtPz = BoxProdotto2.FindViewById<TextView> (Resource.Id.CAT_NumeroPezzi);
TxtPrezzo = BoxProdotto2.FindViewById<TextView> (Resource.Id.CAT_TxtPrezzo);
BoxAddProdotto = BoxProdotto2.FindViewById<LinearLayout> (Resource.Id.BoxAddProdotto);
ImageDisp = BoxProdotto2.FindViewById<ImageView> (Resource.Id.CAT_ImgDisp);
ImgFreccia = BoxProdotto2.FindViewById<ImageView> (Resource.Id.CAT_ImgFreccia);
ImgIncrementa = BoxProdotto2.FindViewById<ImageView> (Resource.Id.imageIncrementa);
ImgDecrementa = BoxProdotto2.FindViewById<ImageView> (Resource.Id.imageDecrementa);
Quantita = BoxProdotto2.FindViewById<EditText> (Resource.Id.editNumerico);
ImageProduct = BoxProdotto2.FindViewById<ImageView> (Resource.Id.CAT_ImageProduct);
TxtPz.Visibility = ViewStates.Invisible;
ImageItem.SetImageResource (Resource.Drawable.feliximage);
#endregion
这是适配器:
namespace ProvaViewPager
{
public class FragmentAdapter : FragmentStatePagerAdapter
{
int mCount;
private FragmentManager mFragmentManager;
public FragmentAdapter (FragmentManager fm) : base (fm)
{
mCount = 200;
mFragmentManager = fm;
}
public override Fragment GetItem (int position)
{
return new SwiftView (position);
}
public override int Count {
get {
return mCount;
}
}
public override Java.Lang.Object InstantiateItem (ViewGroup container, int position)
{
return base.InstantiateItem (container, position);
}
public override void DestroyItem (ViewGroup collection, int position, Java.Lang.Object view)
{
base.DestroyItem(collection,position,view);
}
}
}