DSpotDevelopers / declex

DecleX - Declarative Framework for Android, easier and faster coding.
Other
168 stars 25 forks source link

Problems using FragmentPagerAdapter, @Model and List #51

Open yasmanmesa opened 7 years ago

yasmanmesa commented 7 years ago

I was use a PageAdapter to display a list on each tab of three tabs. When I change the Incoming tab and come back to original tab, the list incomingShiftTrades no load the data from database and throw out a NullPointerException on ShiftTradesIncomingFragment_ when try to do this.models.clear() :

        public void setModels(List<ShiftTrade_> models) {
            if (models!= null) {
                this.models = models;
            } else {
                this.models.clear();
            }
        }

Aditional info this is on ShiftTradesFragment:

    /**
     * Sets shift trades view pager.
     */
    @AfterViews
    void setMyRosterViewPager() {
        PagerAdapter pagerAdapter = new ShiftTradesPageAdapter(getChildFragmentManager());

        viewPager.setAdapter(pagerAdapter);

        tabLayout.setupWithViewPager(viewPager);
    }

on ShiftTradesPageAdapter:

    /**
     * Get the item from the adapter
     * @param position
     * @return Fragment needed
     */
    @Override
    public Fragment getItem(int position) {
        switch (position) {
            case 0:
                return ShiftTradesAllFragment_.builder().build();
            case 1:
                return ShiftTradesIncomingFragment_.builder().build();
            case 2:
                return ShiftTradesOutgoingFragment_.builder().build();
            default:
                return null;
        }
    }

on ShiftTradesIncomingFragment:

    /**
     * The Auth user.
     */
    @Model(lazy = true, query = "")
    @Populator
    List<ShiftTrade_> incomingShiftTrades;
smaugho commented 7 years ago

It would be good to test this with the last changes in DecleX, specially after the change introduced by Issue #57, right now Models will never be null.