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,

fragAf= (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 tagsFragmentfragment=null;
String tag="";
                switch (position) {
                    case0:
                        fragment = newLeads();
                      tag="leads";
                        break;
                    case1:
                    tag="Opportunities"
                        fragment = newOpportunities();
                        break;
                    case2:
                     tag="Accounts";
                        fragment = newAccounts();
                        break;
                    case3:
                        tag="Contactss";
                        fragment = newContactss();
                        break;
                    case4:
                        fragment = newDocuments();
                        break;
                    case5:
                        fragment = newReports();
                    default:
                        break;
                }
                if (fragment != null) {
                    // Getting reference to the FragmentManagerFragmentManagerfragmentManager= getFragmentManager();
                    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).addToBackStack("fragback").commit();
                    // Creating a fragment transactionFragmentTransactionft= 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?"