Quantcast
Channel: Active questions tagged listview - Stack Overflow
Viewing all articles
Browse latest Browse all 683

Content of Fragment not loading every time when using the NavigationDrawer

$
0
0

I have a Navigation Drawer with 6 Fragments. One of them should contain a ListView. I got it to work and I can switch through all the Fragments via the Navigation Drawer. When I press on the one containing the ListView I can see it, just as it should be. However, when I go to the same Fragment (containing the ListView) while I'm in it already, the ListView isn't displayed anymore. This is probably due to the fact, that I set the ListView on the onActivityCreated() method in the Fragment. I'm curious now though, what happens when I press on the same Fragment again. Does the activity stay loaded and the Fragment needs to be inflated again and through this the OnActivityCreated() method isn't called again? And if so, what do I have to do, that the ListView gets displayed again?

My Fragment.class currently looks like this:

public class FahrplanFragment extends Fragment {private ListView listView;private Resources res;private String[] plans;private ArrayAdapter<String> adapter;public FahrplanFragment() {    // Required empty public constructor}@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,                         Bundle savedInstanceState) {    return inflater.inflate(R.layout.fragment_fahrplan, container, false);}@Overridepublic void onActivityCreated(@Nullable Bundle savedInstanceState) {    super.onActivityCreated(savedInstanceState);    listView = (ListView) getActivity().findViewById(R.id.listview_fahrplan);    res = getResources();    plans = res.getStringArray(R.array.plans);    adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1,            android.R.id.text1, plans);    listView.setAdapter(adapter);}}

Viewing all articles
Browse latest Browse all 683

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>