Search in sources :

Example 1 with HomeAdapter

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

the class WechatThirdTabFragment method onLazyInitView.

@Override
public void onLazyInitView(@Nullable Bundle savedInstanceState) {
    super.onLazyInitView(savedInstanceState);
    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) {
            // 通知MainActivity跳转至DetailFragment
            EventBus.getDefault().post(new StartBrotherEvent(DetailFragment.newInstance(mAdapter.getItem(position).getTitle())));
        }
    });
    // Init Datas
    List<Article> articleList = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        Article article = new Article(mTitles[i], mContents[i]);
        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_wechat.listener.OnItemClickListener) Article(me.yokeyword.sample.demo_wechat.entity.Article) ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) StartBrotherEvent(me.yokeyword.sample.demo_wechat.event.StartBrotherEvent) HomeAdapter(me.yokeyword.sample.demo_wechat.adapter.HomeAdapter) 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 HomeAdapter (me.yokeyword.sample.demo_wechat.adapter.HomeAdapter)1 Article (me.yokeyword.sample.demo_wechat.entity.Article)1 StartBrotherEvent (me.yokeyword.sample.demo_wechat.event.StartBrotherEvent)1 OnItemClickListener (me.yokeyword.sample.demo_wechat.listener.OnItemClickListener)1