private void SetRecyclerViewAdapters() { try { MAdapter = new MarketAdapter(Activity) { MarketList = new ObservableCollection <ProductDataObject>() }; MAdapter.ItemClick += MAdapterOnItemClick; LayoutManager = new GridLayoutManager(Activity, 2); LayoutManager.SetSpanSizeLookup(new MySpanSizeLookup(7, 1, 2)); MRecycler.AddItemDecoration(new GridSpacingItemDecoration(2, 10, true)); MRecycler.SetLayoutManager(LayoutManager); var animation = AnimationUtils.LoadAnimation(Activity, Resource.Animation.slideUpAnim); MRecycler.StartAnimation(animation); var sizeProvider = new FixedPreloadSizeProvider(10, 10); var preLoader = new RecyclerViewPreloader <ProductDataObject>(Activity, MAdapter, sizeProvider, 10 /*maxPreload*/); MRecycler.AddOnScrollListener(preLoader); MRecycler.SetAdapter(MAdapter); MRecycler.HasFixedSize = true; MRecycler.SetItemViewCacheSize(10); MRecycler.GetLayoutManager().ItemPrefetchEnabled = true; RecyclerViewOnScrollListener xamarinRecyclerViewOnScrollListener = new RecyclerViewOnScrollListener(LayoutManager); MainScrollEvent = xamarinRecyclerViewOnScrollListener; MainScrollEvent.LoadMoreEvent += MainScrollEventOnLoadMoreEvent; MRecycler.AddOnScrollListener(xamarinRecyclerViewOnScrollListener); MainScrollEvent.IsLoading = false; } catch (Exception e) { Console.WriteLine(e); } }
public void Initialize() { _adapter = new MarketAdapter(); var connectCallback = new DataCallback((DataResult result) => { if (result.IsSuccess) { _isConnected = true; var loginCallback = new DataCallback((DataResult loginResult) => { if (loginResult.IsSuccess) { _isLogin = true; } else { Console.WriteLine("登录失败:{0}", loginResult.Error); } }); _adapter.UserLogin(loginCallback, _investor, _password); Thread.Sleep(100); } else { Console.WriteLine("连接失败:{0}", result.Error); } }); _adapter.Connect(connectCallback, _brokerID, _frontAddr); Thread.Sleep(200); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { try { var view = MyContextWrapper.GetContentView(Context, Settings.Lang, Resource.Layout.Market_Fragment); if (view == null) { view = inflater.Inflate(Resource.Layout.Market_Fragment, container, false); } MainRecyclerView = view.FindViewById <RecyclerView>(Resource.Id.Recyler); Market_Empty = view.FindViewById <LinearLayout>(Resource.Id.Market_LinerEmpty); IconEmpty = view.FindViewById <TextView>(Resource.Id.Market_icon); IMethods.Set_TextViewIcon("2", IconEmpty, "\uf07a"); Btn_AddProduct = view.FindViewById <Button>(Resource.Id.AddProduct_Button); swipeRefreshLayout = view.FindViewById <SwipeRefreshLayout>(Resource.Id.swipeRefreshLayout); swipeRefreshLayout.SetColorSchemeResources(Android.Resource.Color.HoloBlueLight, Android.Resource.Color.HoloGreenLight, Android.Resource.Color.HoloOrangeLight, Android.Resource.Color.HoloRedLight); swipeRefreshLayout.Refreshing = true; swipeRefreshLayout.Enabled = true; MainRecyclerView.Visibility = ViewStates.Visible; Market_Empty.Visibility = ViewStates.Gone; MMarketAdapter = new MarketAdapter(Activity); mLayoutManager = new GridLayoutManager(Activity, 2); MainRecyclerView.SetLayoutManager(mLayoutManager); MainRecyclerView.AddItemDecoration(new GridSpacingItemDecoration(2, 10, true)); var animation = AnimationUtils.LoadAnimation(Activity, Resource.Animation.slideUpAnim); MainRecyclerView.StartAnimation(animation); MMarketAdapter.MarketList = new ObservableCollection <Get_Products_Object.Product>(); MainRecyclerView.SetAdapter(MMarketAdapter); MainRecyclerView.HasFixedSize = (true); MainRecyclerView.SetItemViewCacheSize(5); MainRecyclerView.GetLayoutManager().ItemPrefetchEnabled = true; MainRecyclerView.DrawingCacheEnabled = (true); Get_Data_local(); return(view); } catch (Exception e) { Crashes.TrackError(e); return(null); } }