I'm newbie in programming. I'am adding entries to spinner with data from firebase, everything is ok, but when im fast switching between fragments, error occurs. I know the problem is that im using "getActivity" while using fragment, and the code is still excecuting, while the fragment is not attached anymore. And thats the problem. Is there any posibility to attach adapter to spinner from an activity instead of from fragment? Imo that could avoid that problem, but i dont know how to do that? Here is some code.
ArrayAdapter dania = new ArrayAdapter<>(getActivity(),
android.R.layout.simple_spinner_item, menulist); //I KNOW THAT THE PROBLEM IS HERE getActivity()
ArrayAdapter adodatki = new ArrayAdapter<>(getActivity(),
android.R.layout.simple_spinner_item, menudodatkilist); //I KNOW THAT THE PROBLEM IS HERE getActivity()
dania.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
adodatki.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
danie1spinner.setAdapter(dania);
danie2spinner.setAdapter(adodatki);
I'm open for all suggestions. Thanks for all answers :)