Skip to content Skip to sidebar Skip to footer

Notifydatasetchange Doesnt Work Between Fragments?

I have a doubt i have two fragments namely frag a and frag b of same activity need to pass data from b to a . data from b need to populate listview dynamically i tried notifydatas

Solution 1:

Hi you can update your frag a from frag b by using fragment TAGS from fragB you can call like this,

     fragA f = (fragA)getSupportFragmentManager().findFragmentByTag("yourfragATag");
     // update the list view
     f.updateListView(); 

now how to declare tag....

you can assign tagname at the time when fragment is attaching to container in MainActivity

    ///this is how you can set tags

Fragment fragment = null;
String tag="";
                switch (position) {
                    case 0:
                        fragment = new Leads();
                      tag="leads";
                        break;
                    case 1:
                    tag="Opportunities"
                        fragment = new Opportunities();
                        break;
                    case 2:
                     tag="Accounts";
                        fragment = new Accounts();
                        break;
                    case 3:
                        tag="Contactss";
                        fragment = new Contactss();
                        break;
                    case 4:
                        fragment = new Documents();
                        break;
                    case 5:
                        fragment = new Reports();
                    default:
                        break;
                }
                if (fragment != null) {
                    // Getting reference to the FragmentManager
                    FragmentManager fragmentManager = getFragmentManager();
                    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).addToBackStack("fragback").commit();
                    // Creating a fragment transaction
                    FragmentTransaction ft = fragmentManager.beginTransaction();

                    // Adding a fragment to the fragment transaction
                    ft.replace(R.id.content_frame, fragment,tag);

                    // Committing the transaction
                    ft.commit();

                    // Closing the drawer
                    mDrawerLayout.closeDrawer(mDrawerList);
                } 

:)


Post a Comment for "Notifydatasetchange Doesnt Work Between Fragments?"