Search in sources :

Example 1 with OnItemClickListener

use of me.yokeyword.sample.demo_flow.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) {
            showContent(position);
        }
    });
    if (savedInstanceState != null) {
        mCurrentPosition = savedInstanceState.getInt(SAVE_STATE_POSITION);
        mAdapter.setItemChecked(mCurrentPosition);
    } else {
        mCurrentPosition = 0;
        mAdapter.setItemChecked(0);
    }
}
Also used : OnItemClickListener(me.yokeyword.sample.demo_flow.listener.OnItemClickListener) MenuAdapter(me.yokeyword.sample.demo_flow.adapter.MenuAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 2 with OnItemClickListener

use of me.yokeyword.sample.demo_flow.listener.OnItemClickListener in project Fragmentation by YoKeyword.

the class RecyclerSwipeBackFragment method initView.

private void initView(View view) {
    mRecy = (RecyclerView) view.findViewById(R.id.recy);
    mToolbar = (Toolbar) view.findViewById(R.id.toolbar);
    _initToolbar(mToolbar);
    mAdapter = new PagerAdapter(_mActivity);
    LinearLayoutManager manager = new LinearLayoutManager(_mActivity);
    mRecy.setLayoutManager(manager);
    mRecy.setAdapter(mAdapter);
    mAdapter.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(int position, View view) {
            start(FirstSwipeBackFragment.newInstance());
        }
    });
    // Init Datas
    List<String> items = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        String item;
        item = getString(R.string.favorite) + " " + i;
        items.add(item);
    }
    mAdapter.setDatas(items);
}
Also used : OnItemClickListener(me.yokeyword.sample.demo_flow.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_flow.adapter.PagerAdapter)

Example 3 with OnItemClickListener

use of me.yokeyword.sample.demo_flow.listener.OnItemClickListener in project Fragmentation by YoKeyword.

the class PagerChildFragment method initView.

private void initView(View view) {
    mRecy = (RecyclerView) view.findViewById(R.id.recy);
    mAdapter = new PagerAdapter(_mActivity);
    LinearLayoutManager manager = new LinearLayoutManager(_mActivity);
    mRecy.setLayoutManager(manager);
    mRecy.setAdapter(mAdapter);
    mAdapter.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(int position, View view) {
            if (getParentFragment() instanceof DiscoverFragment) {
                ((DiscoverFragment) getParentFragment()).start(CycleFragment.newInstance(1));
            }
        }
    });
    mRecy.post(new Runnable() {

        @Override
        public void run() {
            // Init Datas
            List<String> items = new ArrayList<>();
            for (int i = 0; i < 20; i++) {
                String item;
                if (mFrom == 0) {
                    item = getString(R.string.recommend) + " " + i;
                } else if (mFrom == 1) {
                    item = getString(R.string.hot) + " " + i;
                } else {
                    item = getString(R.string.favorite) + " " + i;
                }
                items.add(item);
            }
            mAdapter.setDatas(items);
        }
    });
}
Also used : OnItemClickListener(me.yokeyword.sample.demo_flow.listener.OnItemClickListener) ArrayList(java.util.ArrayList) List(java.util.List) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) PagerAdapter(me.yokeyword.sample.demo_flow.adapter.PagerAdapter)

Example 4 with OnItemClickListener

use of me.yokeyword.sample.demo_flow.listener.OnItemClickListener in project Fragmentation by YoKeyword.

the class HomeFragment method initView.

private void initView(View view) {
    mToolbar = (Toolbar) view.findViewById(R.id.toolbar);
    mRecy = (RecyclerView) view.findViewById(R.id.recy);
    mTitles = getResources().getStringArray(R.array.array_title);
    mContents = getResources().getStringArray(R.array.array_content);
    mToolbar.setTitle(R.string.home);
    initToolbarNav(mToolbar, true);
    mToolbar.inflateMenu(R.menu.home);
    mToolbar.setOnMenuItemClickListener(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) {
            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);
}
Also used : OnItemClickListener(me.yokeyword.sample.demo_flow.listener.OnItemClickListener) Article(me.yokeyword.sample.demo_flow.entity.Article) ArrayList(java.util.ArrayList) HomeAdapter(me.yokeyword.sample.demo_flow.adapter.HomeAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)4 RecyclerView (android.support.v7.widget.RecyclerView)4 View (android.view.View)4 OnItemClickListener (me.yokeyword.sample.demo_flow.listener.OnItemClickListener)4 ArrayList (java.util.ArrayList)3 PagerAdapter (me.yokeyword.sample.demo_flow.adapter.PagerAdapter)2 List (java.util.List)1 HomeAdapter (me.yokeyword.sample.demo_flow.adapter.HomeAdapter)1 MenuAdapter (me.yokeyword.sample.demo_flow.adapter.MenuAdapter)1 Article (me.yokeyword.sample.demo_flow.entity.Article)1