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;
}
}
});
}
Aggregations