Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int layoutId = R.layout.list_item;
- int spanCount = 2;
- switch (item.getItemId()) {
- case R.id.linearVertical: // Vertical scrollable using LinearLayoutManager.
- recyclerView.setLayoutManager(new LinearLayoutManager(this));
- break;
- case R.id.linearHorizontal: // Horizontal scrollable using LinearLayoutManager.
- layoutId = R.layout.list_item_horizontal;
- recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
- break;
- case R.id.gridviewVertical: // Vertical scrollable using GridLayoutManager.
- recyclerView.setLayoutManager(new GridLayoutManager(this, spanCount));
- break;
- case R.id.gridviewHorizontal: // Horizontal scrollable using GridLayoutManager.
- layoutId = R.layout.list_item_horizontal;
- recyclerView.setLayoutManager(new GridLayoutManager(this, spanCount, LinearLayoutManager.HORIZONTAL, false));
- break;
- case R.id.staggeredGridviewVertical: // Vertical scrollable using StaggeredGridLayoutManager.
- recyclerView.setLayoutManager(new StaggeredGridLayoutManager(spanCount, StaggeredGridLayoutManager.VERTICAL));
- break;
- case R.id.staggeredGridviewHorizontal: // Horizontal scrollable using StaggeredGridLayoutManager.
- layoutId = R.layout.list_item_horizontal;
- recyclerView.setLayoutManager(new StaggeredGridLayoutManager(spanCount, StaggeredGridLayoutManager.HORIZONTAL));
- break;
- }
- adapter = new AnimalAdapter(animalList, layoutId);
- recyclerView.setAdapter(adapter);
- return super.onOptionsItemSelected(item);
- }
Add Comment
Please, Sign In to add comment