Search in sources :

Example 1 with Article

use of me.yokeyword.sample.demo_flow.entity.Article 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)

Example 2 with Article

use of me.yokeyword.sample.demo_flow.entity.Article in project Fragmentation by YoKeyword.

the class HomeAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
    Article item = mItems.get(position);
    holder.tvTitle.setText(item.getTitle());
    holder.tvContent.setText(item.getContent());
}
Also used : Article(me.yokeyword.sample.demo_flow.entity.Article)

Aggregations

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