Exemple #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            // Create your application here
            SetContentView(Resource.Layout.main);
            Log.Info("GCS", "onCreate");

            _seekBar = FindViewById <SeekBar>(Resource.Id.seekBar1);
            _seekBar.SetOnTouchListener(this);


            mRadioGroup = this.FindViewById <RadioGroup>(Resource.Id.orientation_type);// (RadioGroup)findViewById(R.id.orientation_type);
            mRadioGroup.SetOnCheckedChangeListener(this);

            mPageTotal         = (TextView)FindViewById(Resource.Id.page_total);
            mPageCurrent       = (TextView)FindViewById(Resource.Id.page_current);
            t_page_bar_process = FindViewById <TextView>(Resource.Id.page_bar_process);
            mLayoutManager     = new PagerGridLayoutManager(mRows, mColumns, PagerGridLayoutManager
                                                            .HORIZONTAL);


            // 系统带的 RecyclerView,无需自定义
            mRecyclerView = (RecyclerView)FindViewById(Resource.Id.recycler_view);

            // 水平分页布局管理器
            mLayoutManager.SetPageListener(this);    // 设置页面变化监听器
            mRecyclerView.SetLayoutManager(mLayoutManager);

            // 设置滚动辅助工具
            PagerGridSnapHelper pageSnapHelper = new PagerGridSnapHelper();

            pageSnapHelper.AttachToRecyclerView(mRecyclerView);

            // 如果需要查看调试日志可以设置为true,一般情况忽略即可
            PagerConfig.SetShowLog(true);
            List <string> data = new List <string>();

            for (int i = 1; i <= 15; i++)
            {
                data.Add(i + "");
            }
            // 使用原生的 Adapter 即可
            mAdapter = new MainItemAdapter(data);
            RecyclerView.AdapterDataObserver observer = new DataObserverModel(mAdapter);
            mAdapter.RegisterAdapterDataObserver(observer);
            mRecyclerView.SetAdapter(mAdapter);

            Button btn_addone = this.FindViewById <Button>(Resource.Id.AddOneFunc);

            btn_addone.Click += delegate
            {
                mAdapter.items.Add("add");
                mAdapter.NotifyDataSetChanged();
            };
        }
Exemple #2
0
 public DataObserverModel(MainItemAdapter item)
 {
     _myItem = item;
 }