Search in sources :

Example 1 with HomeAdapter

use of me.yokeyword.sample.demo_zhihu.adapter.HomeAdapter in project Fragmentation by YoKeyword.

the class FirstPagerFragment method initView.

private void initView(View view) {
    mRecy = (RecyclerView) view.findViewById(R.id.recy);
    mRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.refresh_layout);
    mRefreshLayout.setColorSchemeResources(R.color.colorPrimary);
    mRefreshLayout.setOnRefreshListener(this);
    mAdapter = new HomeAdapter(_mActivity);
    LinearLayoutManager manager = new LinearLayoutManager(_mActivity);
    mRecy.setLayoutManager(manager);
    mRecy.setAdapter(mAdapter);
    mAdapter.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(int position, View view, RecyclerView.ViewHolder vh) {
            // 这里的DetailFragment在flow包里
            // 这里是父Fragment启动,要注意 栈层级
            ((SupportFragment) getParentFragment()).start(DetailFragment.newInstance(mAdapter.getItem(position).getTitle()));
        }
    });
    // Init Datas
    List<Article> articleList = new ArrayList<>();
    for (int i = 0; i < 15; i++) {
        int index = (int) (Math.random() * 3);
        Article article = new Article(mTitles[index], mContents[index]);
        articleList.add(article);
    }
    mAdapter.setDatas(articleList);
    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) {
                mAtTop = true;
            } else {
                mAtTop = false;
            }
        }
    });
}
Also used : OnItemClickListener(me.yokeyword.sample.demo_zhihu.listener.OnItemClickListener) Article(me.yokeyword.sample.demo_zhihu.entity.Article) ArrayList(java.util.ArrayList) HomeAdapter(me.yokeyword.sample.demo_zhihu.adapter.HomeAdapter) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

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 HomeAdapter (me.yokeyword.sample.demo_zhihu.adapter.HomeAdapter)1 Article (me.yokeyword.sample.demo_zhihu.entity.Article)1 OnItemClickListener (me.yokeyword.sample.demo_zhihu.listener.OnItemClickListener)1