Question

There are dozens of this kind of threads, but i couldnt find and solution for my problem (at least working one).

So i have 3 fragments in my viewpager, my last (3rd) fragment is basically a friendlist, i also have a button with which i open a new fragment, where i handle search/request etc. In that fragment i have "back button", i get back to my "3rd" fragment in a viewpager with getFragmentManager().popBackStack(). How can i pass boolean value or something back to the "3rd" fragment?

I tried with manually calling onPause and onResume methods of the 3rd fragment, but then my list is empty. Also no methods of the 3rd fragment is called when i popbackstack.

This is my code

3rd fragment

This is how i open new fragment

    ImageButton friendsButton = (ImageButton) v.findViewById(R.id.friendsButton);
    friendsButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            SearchActivity configDetailSectionFragment = new SearchActivity();
            FragmentManager fragmentManager = getFragmentManager();

            FragmentTransaction transaction = fragmentManager.beginTransaction();
            transaction.add(R.id.item_detail_container, configDetailSectionFragment);
            transaction.addToBackStack(null);
            transaction.commit();
        }
    });

and this is how i get back to the 3rd fragment

    ImageButton backButton=(ImageButton)rootView.findViewById(R.id.backButton);
    backButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {


            getFragmentManager().popBackStack();

        } });

My methods for filling exlistview work fine, just no methods are called after popbackstack, so i could update my list.

What should i change and when and where should i call listadapter.notifyDataSetChanged()?

Was it helpful?

Solution

Using add fragment method with addBackStack, on poBackStack previous fragment's onResume will not get called. So if you are using addBackStack and popBackStack, and you want to call onResume of your previous fragment then you have to use replace instead of add. So your code just changes like - transaction.replace(R.id.item_detail_container,configDetailSectionFragment);

once you did this you can use your onResume method to refresh list.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top