emilsjolander / android-FlipView

A small, easy to use android library for implementing flipping between views as seen in the popular Flipboard application
Apache License 2.0
925 stars 273 forks source link

FlipView Adapter not Updating #62

Open Kolokodess opened 9 years ago

Kolokodess commented 9 years ago

The adapter of a flipview is set onCreate. Everything works fine. The user is meant to select some items on another activity which would update the items on the flipview. I implemented this by changing the adapter of the flipView when onResume is called and the dismiss activity is the selectionActivity. The code is executed but it does not reflect on the flipView items.

What i do on onCreate

@Override 'public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); View rootView = inflater.inflate(R.layout.flip_main, container, false); mFlipView = (FlipView) rootView.findViewById(R.id.flip_view);

        mAdapter = new FlipAdapter(getActivity(),getHomeItems(), getFragmentManager());
        mAdapter.setCallback(this);
        mFlipView.setAdapter(mAdapter);
        mFlipView.setOnFlipListener(this);
        if (isFirstShown) {
            mFlipView.peakNext(false);
            isFirstShown = false;
        }
        mFlipView.setOverFlipMode(OverFlipMode.RUBBER_BAND);
        mFlipView.setEmptyView(getActivity().findViewById(R.id.empty_view));
        mFlipView.setOnOverFlipListener(this);
        return rootView;
    }

what is called after the user makes selection

FlipAdapterTest mAdapter = new FlipAdapterTest(getActivity(), getHomeItems(), getFragmentManager()); mFlipView.removeAllViews(); mFlipView.setAdapter(mAdapter);

ayltai commented 9 years ago

Is it possible that your fragment is being created again when your main activity resumes, such that onCreateView() is called and mFlipView is re-created? Can you post the code you use to create and add your fragment?

BTW, why are you calling super.onCreate() in onCreateView()? And, you don't need to call mFlipView.removeAllViews(), because it will be called in mFlipView.setAdapter().