1

I am developing an app in which the main screen is entirely built from the response of a webserver. We used to display this content in a recycler view, but as the views are very complex and share almost nothing in common, the scroll was not smooth as the recycling behaviour was very expensive.

I decided to create a Fragment for each type of view that I have to expose and add them to a LinearLayout inside a ScrollView. The result was amazing. No recycling made the scroll very smooth and orientation change got a lot better too, as fragments have a lifecycle and their data can be serialized. However, I got a new problem:

https://code.google.com/p/android/issues/detail?id=69403

And from what I understand from this SO question:

Android multiple fragment transaction ordering

I would have to include the source of the support library in order to that workaround and I would't like that unless it is an absolute necessity.

Does anyone know any other way of how to display this kind of dynamic content?

EDIT: This is the code that I have right now:

        FragmentTransaction tx = mFragmentManager.beginTransaction();
        mContainerList = new ArrayList<>(containers);

        if(mFragmentManager.getFragments() != null) {
            for (Fragment f : mFragmentManager.getFragments())
                if (f != null)
                    tx.remove(f);
            Collections.reverse(mContainerList);
        }

        for(final InitResult.Container c : mContainerList) {
            InitFragment fragment = null;
            switch (c.getType()) {
                case InitResult.Container.HORIZONTAL_LIST:
                    if (c.getItems() != null && c.getItems().size() > 0 && c.getItems().get(0).getType().equals(InitResult.Container.BANNER))
                        fragment = new InitBannerFragment();
                    else
                        fragment = new InitHListFragment();
                    break;
                case InitResult.Container.GRID:
                    fragment = new InitGridFragment();
                    break;
                case InitResult.Container.BANNER:
                    fragment = new InitBannerFragment();
                    break;
                case InitResult.Container.PROMOTIONAL:
                    fragment = new InitPromotionalFragment();
                    break;
                case InitResult.Container.PROTEGE:
                    fragment = new InitProtegeFragment();
                    break;
                case InitResult.Container.PROTEGE_ACTIVE:
                    fragment = new InitProtegeActiveFragment();
                    break;
            }

            if (fragment != null) {
                fragment.setInitContainer(c);
                tx.add(containerList.getId(), fragment);
            }
        }

        tx.commitAllowingStateLoss();
        mFragmentManager.executePendingTransactions();

Whenever the screen is refreshed, I run this code. Notice that if I'm not doing this for the first time, I need to reverse the container list so it is listed int the desired order.

My problem happens when a new item comes from the server, not just a list with updated content. If this new item comes, it won't be placed in the desired order, it will be placed at the end of the list.

Community
  • 1
  • 1
Fabio Picchi
  • 1,202
  • 2
  • 10
  • 22
  • Your question is not very clear. Just linking to a bug report doesn't necessarily explain how it is affecting your specific scenario and your code. It would be better to describe the exact problem that is happening in your own code (and show your code). Then others could more easily tailor a solution to your specific situation. – NoChinDeluxe Dec 09 '15 at 22:08
  • Thank you for the comment. Excuse me for not being very clear. I added my current solution to the question. – Fabio Picchi Dec 10 '15 at 12:21
  • İ think you need to refill your mContainerList and make a new fragment transaction to fill screen again – Jemshit Dec 12 '15 at 09:28
  • The code I posted is run every time mContainerList is changed, so I already do that :) – Fabio Picchi Dec 14 '15 at 13:54

0 Answers0