@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if (getArguments() != null) { enemy = Parcels.unwrap(getArguments().getParcelable("enemy")); } preferences = PreferenceManager.getDefaultSharedPreferences(Singleton.getInstance().getContext()); isGrid = preferences.getBoolean("isGrid", true); realm = Realm.getDefaultInstance(); if (monsterListAll == null) { monsterListAll = new ArrayList<>(); } monsterListAll.clear(); monsterListAll.addAll(realm.where(BaseMonster.class).greaterThan("monsterId", 0).findAll()); if (monsterList == null) { monsterList = new ArrayList<>(); } fastScroller.setRecyclerView(monsterListView); if (isGrid) { monsterListView.setLayoutManager( new StaggeredGridLayoutManager(5, StaggeredGridLayoutManager.VERTICAL)); } else { monsterListView.setLayoutManager( new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL)); } monsterPortraitListRecycler = new MonsterPortraitListRecycler( getContext(), monsterList, monsterListView, isGrid, realm, enemy); monsterListView.setAdapter(monsterPortraitListRecycler); getActivity().setTitle("Select Portrait"); }