vendredi 29 mai 2015

Call viewpager adapter's NotifyDataSetChanged from the child fragment

I'm trying to do a challange from Android Big Nerd Ranch book on using action bars. and i'm getting the below exception when i try to delete:

java.lang.IllegalStateException: The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged!

below is the code i handle the delete on CrimeFragment.java

 @Override
                       public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                           switch (item.getItemId())
                           {
                               case R.id.menu_item_delete_crime:
                                   CrimeLab.get(getActivity()).deleteCrime(mCrime);
                                   mode.finish();

                                    return true;
                               default:
                                   return false;
                           }

                       }

My target SDK is 21 ad the AVD is running lollipop. how do i get around this. much appreciate any help.

I know we can do as suggested in this post. but that would couple my fragment for the specific activity. anyway to overcome this ?

Aucun commentaire:

Enregistrer un commentaire