Skip to content

Instantly share code, notes, and snippets.

@mzgreen
Created June 23, 2015 10:50
Show Gist options
  • Save mzgreen/2ad432f2097b151cf0cd to your computer and use it in GitHub Desktop.
Save mzgreen/2ad432f2097b151cf0cd to your computer and use it in GitHub Desktop.
HideOnScrollExample - PartThreeFragment
public class PartThreeFragment extends Fragment {
public final static String ITEMS_COUNT_KEY = "PartThreeFragment$ItemsCount";
public static PartThreeFragment createInstance(int itemsCount) {
PartThreeFragment partThreeFragment = new PartThreeFragment();
Bundle bundle = new Bundle();
bundle.putInt(ITEMS_COUNT_KEY, itemsCount);
partThreeFragment.setArguments(bundle);
return partThreeFragment;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
RecyclerView recyclerView = (RecyclerView) inflater.inflate(
R.layout.fragment_part_three, container, false);
setupRecyclerView(recyclerView);
return recyclerView;
}
private void setupRecyclerView(RecyclerView recyclerView) {
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
RecyclerAdapter recyclerAdapter = new RecyclerAdapter(createItemList());
recyclerView.setAdapter(recyclerAdapter);
}
private List<String> createItemList() {
List<String> itemList = new ArrayList<>();
Bundle bundle = getArguments();
if(bundle!=null) {
int itemsCount = bundle.getInt(ITEMS_COUNT_KEY);
for (int i = 0; i < itemsCount; i++) {
itemList.add("Item " + i);
}
}
return itemList;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment