Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RecipesFragment extends Fragment implements Callback<List<Recipe>> {
- private FragmentRecipesBinding mBinding = null;
- public RecipesFragment() {}
- @Nullable
- @Override
- public View onCreateView(
- @NonNull LayoutInflater inflater,
- @Nullable ViewGroup container,
- @Nullable Bundle savedInstanceState)
- {
- mBinding = DataBindingUtil.inflate(
- inflater,
- R.layout.fragment_recipes,
- container,
- false);
- LinearLayoutManager layoutManager =
- new LinearLayoutManager(getContext(),
- LinearLayoutManager.VERTICAL,
- false);
- AppAdapter<Recipe, RecipeView<Recipe>> adapter = new AppAdapter<>();
- mBinding.rvRecipes.setAdapter(adapter);
- mBinding.rvRecipes.setLayoutManager(layoutManager);
- mBinding.rvRecipes.setHasFixedSize(true);
- return mBinding.getRoot();
- }
- @Override
- public void onResponse(Call<List<Recipe>> call, Response<List<Recipe>> response) {
- if (response != null && response.body() != null) {
- AppAdapter<Recipe, RecipeView<Recipe>> adapter = null;
- // Warning of unchecked cast.
- if (mBinding.rvRecipes.getAdapter() instanceof AppAdapter) {
- adapter = (AppAdapter) mBinding.rvRecipes.getAdapter();
- adapter.setData(response.body());
- }
- }
- }
- @Override
- public void onFailure(Call<List<Recipe>> call, Throwable t) {
- }
- }
Add Comment
Please, Sign In to add comment