roughike / BottomBar

(Deprecated) A custom view component that mimics the new Material Design Bottom Navigation pattern.
Apache License 2.0
8.43k stars 1.51k forks source link

Going from 4 items to 3 items causes an NPE #843

Open FridayShamblen opened 6 years ago

FridayShamblen commented 6 years ago

A beautiful bottom bar. Thank you.

I am switching between an xml resource with 4 tabs to one with 3 tabs dynamically (so if logged in, 3 tabs, if logged out, 4 tabs). When going from an xml file with 4 tabs to one with 3 tabs, an NPE is triggered. It is because oldTab is no longer available to deselect (I have lost the error output on this at the moment), I believe it is line 921.

Here is a code snippet: should I be instantiating this differently or is there a way to "refresh" the object so it forgets about the oldTab?

` int xmlFile;

        if (mIsPremium) {
            //play, signin, ach, leader, twit
            xmlFile = R.xml.bottom_tabs_signed_in_paid;

        } else { //fremium
            //play, signin, ach, leader, twit, buy
            xmlFile = R.xml.bottom_tabs_signed_in_free;
        }

   bottomBar = (BottomBar) findViewById(R.id.bottomBar);
    bottomBar.setItems(xmlFile);

    bottomBar.setOnTabSelectListener(new OnTabSelectListener() {
        @Override
        public void onTabSelected(@IdRes int tabId) {
            tabResponse(tabId);
        }
    }, false);

    bottomBar.setOnTabReselectListener(new OnTabReselectListener() {
        @Override
        public void onTabReSelected(@IdRes int tabId) {
            tabResponse(tabId);
        }
    });

`