Search in sources :

Example 1 with MainItemAdapter

use of com.yanzhenjie.swiperecyclerview.adapter.MainItemAdapter in project SwipeRecyclerView by yanzhenjie.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, LinearLayoutManager.VERTICAL));
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {

        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            outRect.set(10, 10, 10, 15);
        }
    });
    List<String> titles = Arrays.asList(getResources().getStringArray(R.array.main_item));
    List<String> descriptions = Arrays.asList(getResources().getStringArray(R.array.main_item_des));
    MainItemAdapter mainItemAdapter = new MainItemAdapter(titles, descriptions);
    mainItemAdapter.setOnItemClickListener(this);
    recyclerView.setAdapter(mainItemAdapter);
}
Also used : Rect(android.graphics.Rect) RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) MainItemAdapter(com.yanzhenjie.swiperecyclerview.adapter.MainItemAdapter) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

Rect (android.graphics.Rect)1 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 RecyclerView (android.support.v7.widget.RecyclerView)1 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 MainItemAdapter (com.yanzhenjie.swiperecyclerview.adapter.MainItemAdapter)1