add getactivity

This commit is contained in:
Sem van der Hoeven
2021-01-12 14:47:09 +01:00
parent baf30b5dda
commit 5e2d49ac08
8 changed files with 42 additions and 37 deletions

View File

@@ -43,7 +43,8 @@ public class LocationFragment extends Fragment {
this.backButton = view.findViewById(R.id.location_back_button);
this.backButton.setOnClickListener(v -> {
HomeFragment homeFragment = new HomeFragment();
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, homeFragment).addToBackStack(null).commit();
if (getActivity() != null)
getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, homeFragment).addToBackStack(null).commit();
});
//Loads the location list
@@ -58,7 +59,8 @@ public class LocationFragment extends Fragment {
//Gives the clicked location to the adapter
locationBundle.putParcelable("location", this.locationList.get(clickedPosition));
locationDetailFragment.setArguments(locationBundle);
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, locationDetailFragment).addToBackStack(null).commit();
if (getActivity() != null)
getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, locationDetailFragment).addToBackStack(null).commit();
});
this.locationRecyclerView.setLayoutManager(this.layoutManager);