Search in sources :

Example 1 with PagerAdapter

use of me.yokeyword.sample.demo_wechat.adapter.PagerAdapter in project Fragmentation by YoKeyword.

the class FirstPagerFragment method initView.

private void initView(View view) {
    EventBus.getDefault().register(this);
    mRecy = (RecyclerView) view.findViewById(R.id.recy);
    mRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.refresh_layout);
    mRefreshLayout.setOnRefreshListener(this);
    mAdapter = new PagerAdapter(_mActivity);
    mRecy.setHasFixedSize(true);
    LinearLayoutManager manager = new LinearLayoutManager(_mActivity);
    mRecy.setLayoutManager(manager);
    mRecy.setAdapter(mAdapter);
    mRecy.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            mScrollTotal += dy;
            if (mScrollTotal <= 0) {
                mInAtTop = true;
            } else {
                mInAtTop = false;
            }
        }
    });
    mAdapter.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(int position, View view, RecyclerView.ViewHolder holder) {
            // 通知MainActivity跳转至CycleFragment
            EventBus.getDefault().post(new StartBrotherEvent(CycleFragment.newInstance(1)));
        }
    });
    // Init Datas
    List<String> items = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        String item = "联系人 " + i;
        items.add(item);
    }
    mAdapter.setDatas(items);
}
Also used : OnItemClickListener(me.yokeyword.sample.demo_wechat.listener.OnItemClickListener) ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) PagerAdapter(me.yokeyword.sample.demo_wechat.adapter.PagerAdapter) StartBrotherEvent(me.yokeyword.sample.demo_wechat.event.StartBrotherEvent) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ArrayList (java.util.ArrayList)1 PagerAdapter (me.yokeyword.sample.demo_wechat.adapter.PagerAdapter)1 StartBrotherEvent (me.yokeyword.sample.demo_wechat.event.StartBrotherEvent)1 OnItemClickListener (me.yokeyword.sample.demo_wechat.listener.OnItemClickListener)1