Guest User

Untitled

a guest
Oct 22nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. @Override
  2. public boolean onOptionsItemSelected(MenuItem item) {
  3. // Handle action bar item clicks here. The action bar will
  4. // automatically handle clicks on the Home/Up button, so long
  5. // as you specify a parent activity in AndroidManifest.xml.
  6.  
  7. int layoutId = R.layout.list_item;
  8. int spanCount = 2;
  9. switch (item.getItemId()) {
  10. case R.id.linearVertical: // Vertical scrollable using LinearLayoutManager.
  11. recyclerView.setLayoutManager(new LinearLayoutManager(this));
  12. break;
  13. case R.id.linearHorizontal: // Horizontal scrollable using LinearLayoutManager.
  14. layoutId = R.layout.list_item_horizontal;
  15. recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
  16. break;
  17. case R.id.gridviewVertical: // Vertical scrollable using GridLayoutManager.
  18. recyclerView.setLayoutManager(new GridLayoutManager(this, spanCount));
  19. break;
  20. case R.id.gridviewHorizontal: // Horizontal scrollable using GridLayoutManager.
  21. layoutId = R.layout.list_item_horizontal;
  22. recyclerView.setLayoutManager(new GridLayoutManager(this, spanCount, LinearLayoutManager.HORIZONTAL, false));
  23. break;
  24. case R.id.staggeredGridviewVertical: // Vertical scrollable using StaggeredGridLayoutManager.
  25. recyclerView.setLayoutManager(new StaggeredGridLayoutManager(spanCount, StaggeredGridLayoutManager.VERTICAL));
  26. break;
  27. case R.id.staggeredGridviewHorizontal: // Horizontal scrollable using StaggeredGridLayoutManager.
  28. layoutId = R.layout.list_item_horizontal;
  29. recyclerView.setLayoutManager(new StaggeredGridLayoutManager(spanCount, StaggeredGridLayoutManager.HORIZONTAL));
  30. break;
  31. }
  32. adapter = new AnimalAdapter(animalList, layoutId);
  33. recyclerView.setAdapter(adapter);
  34.  
  35. return super.onOptionsItemSelected(item);
  36. }
Add Comment
Please, Sign In to add comment