package com.kanshu.kanshu;
/**
* Created by zhou on 1/15/15.
*/
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.kanshu.kanshu.model.Article;
import java.util.ArrayList;
import java.util.List;
/**
* A placeholder fragment containing a simple view.
*/
public class ArticleListFragment extends Fragment {
private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private LinearLayoutManager mLayoutManager;
/**
* The fragment argument representing the section number for this
* fragment.
*/
private static final String ARG_SECTION_NUMBER = "section_number";
/**
* Returns a new instance of this fragment for the given section
* number.
*/
public static ArticleListFragment newInstance(int sectionNumber) {
ArticleListFragment fragment = new ArticleListFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
public ArticleListFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_article, container, false);
mRecyclerView = (RecyclerView) rootView.findViewById(R.id.my_recycler_view);
// use a linear layout manager
mLayoutManager = new LinearLayoutManager(getActivity());
mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(mLayoutManager);
//@todo use the real data to replace dummy data
List<Article> articles = new ArrayList<Article>();
articles.add(new Article());
articles.add(new Article());
articles.add(new Article());
articles.add(new Article());
articles.add(new Article());
articles.add(new Article());
articles.add(new Article());
articles.add(new Article());
articles.add(new Article());
articles.add(new Article());
// specify an adapter
mAdapter = new ArticleAdapter(articles);
mRecyclerView.setAdapter(mAdapter);
return rootView;
}
}