Search in sources :

Example 1 with ArticleAdapter

use of com.forcelain.android.awesomerecyclerview.view.ArticleAdapter in project AwesomeRecyclerView by forceLain.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    layoutManager = new AwesomeLayoutManager(this);
    recyclerView.setLayoutManager(layoutManager);
    ArticleAdapter adapter = new ArticleAdapter();
    recyclerView.setAdapter(adapter);
    dataProvider = new FakeDataProvider(this);
    List<Article> articles = dataProvider.getArticles();
    adapter.setArticles(articles);
    recyclerView.setChildDrawingOrderCallback(new RecyclerView.ChildDrawingOrderCallback() {

        @Override
        public int onGetChildDrawingOrder(int childCount, int i) {
            return childCount - i - 1;
        }
    });
    adapter.setItemClickListener(new ArticleAdapter.OnItemClickListener() {

        @Override
        public void onItemClicked(int pos) {
            layoutManager.openItem(pos);
        }
    });
    findViewById(R.id.test_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            recyclerView.smoothScrollToPosition(4);
        }
    });
}
Also used : FakeDataProvider(com.forcelain.android.awesomerecyclerview.data.FakeDataProvider) Article(com.forcelain.android.awesomerecyclerview.model.Article) RecyclerView(android.support.v7.widget.RecyclerView) AwesomeLayoutManager(com.forcelain.android.awesomerecyclerview.view.AwesomeLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) ArticleAdapter(com.forcelain.android.awesomerecyclerview.view.ArticleAdapter)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 FakeDataProvider (com.forcelain.android.awesomerecyclerview.data.FakeDataProvider)1 Article (com.forcelain.android.awesomerecyclerview.model.Article)1 ArticleAdapter (com.forcelain.android.awesomerecyclerview.view.ArticleAdapter)1 AwesomeLayoutManager (com.forcelain.android.awesomerecyclerview.view.AwesomeLayoutManager)1