use of me.yokeyword.sample.demo_zhihu.listener.OnItemClickListener in project Fragmentation by YoKeyword.
the class FirstHomeFragment method initView.
private void initView(View view) {
mToolbar = (Toolbar) view.findViewById(R.id.toolbar);
mRecy = (RecyclerView) view.findViewById(R.id.recy);
mRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.refresh_layout);
mFab = (FloatingActionButton) view.findViewById(R.id.fab);
mToolbar.setTitle(R.string.home);
mRefreshLayout.setColorSchemeResources(R.color.colorPrimary);
mRefreshLayout.setOnRefreshListener(this);
mAdapter = new FirstHomeAdapter(_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) {
FirstDetailFragment fragment = FirstDetailFragment.newInstance(mAdapter.getItem(position));
// LOLLIPOP(5.0)系统的 SharedElement支持有 系统BUG, 这里判断大于 > LOLLIPOP
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
setExitTransition(new Fade());
fragment.setEnterTransition(new Fade());
fragment.setSharedElementReturnTransition(new DetailTransition());
fragment.setSharedElementEnterTransition(new DetailTransition());
// 25.1.0以下的support包,Material过渡动画只有在进栈时有,返回时没有;
// 25.1.0+的support包,SharedElement正常
extraTransaction().addSharedElement(((FirstHomeAdapter.VH) vh).img, getString(R.string.image_transition)).addSharedElement(((FirstHomeAdapter.VH) vh).tvTitle, "tv").start(fragment);
} else {
start(fragment);
}
}
});
// Init Datas
List<Article> articleList = new ArrayList<>();
for (int i = 0; i < 8; i++) {
int index = i % 5;
Article article = new Article(mTitles[index], mImgRes[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) {
mInAtTop = true;
} else {
mInAtTop = false;
}
if (dy > 5) {
mFab.hide();
} else if (dy < -5) {
mFab.show();
}
}
});
mFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(_mActivity, "Action", Toast.LENGTH_SHORT).show();
}
});
}
use of me.yokeyword.sample.demo_zhihu.listener.OnItemClickListener 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);
mTitles = getResources().getStringArray(R.array.array_title);
mContents = getResources().getStringArray(R.array.array_content);
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;
}
}
});
}
use of me.yokeyword.sample.demo_zhihu.listener.OnItemClickListener in project Fragmentation by YoKeyword.
the class MenuListFragment method onActivityCreated.
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
LinearLayoutManager manager = new LinearLayoutManager(_mActivity);
mRecy.setLayoutManager(manager);
mAdapter = new MenuAdapter(_mActivity);
mRecy.setAdapter(mAdapter);
mAdapter.setDatas(mMenus);
mAdapter.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(int position, View view, RecyclerView.ViewHolder vh) {
showContent(position);
}
});
if (savedInstanceState != null) {
mCurrentPosition = savedInstanceState.getInt(SAVE_STATE_POSITION);
mAdapter.setItemChecked(mCurrentPosition);
} else {
mCurrentPosition = 0;
mAdapter.setItemChecked(0);
}
}
Aggregations