bufferapp / AdaptableBottomNavigation

A simpler way for implementing the Bottom Navigation View on Android
829 stars 73 forks source link

Crash when not overriding `clearItem()` inside `FragmentAdapter` #9

Open Gnzlt opened 7 years ago

Gnzlt commented 7 years ago

I found a crash which occurs when using a custom adapter that extends from FragmentAdapter.

Whenever the ViewSwapper makes a call to clearItem() it throws a custom UnsupportedOperationException inside ViewSwapperAdapter since clearItem() is not overrided by default.

E/AndroidRuntime: FATAL EXCEPTION: main
 Process: com.example, PID: 12089
 java.lang.UnsupportedOperationException: Required method destroyItem was not overridden
     at org.buffer.adaptablebottomnavigation.adapter.ViewSwapperAdapter.destroyItem(ViewSwapperAdapter.java:196)
     at org.buffer.adaptablebottomnavigation.adapter.ViewSwapperAdapter.clearItem(ViewSwapperAdapter.java:126)
     at org.buffer.adaptablebottomnavigation.view.ViewSwapper.showItemAt(ViewSwapper.java:122)
     at org.buffer.adaptablebottomnavigation.view.AdaptableBottomNavigationView$ViewSwapperOnItemSelectedListener.onNavigationItemSelected(AdaptableBottomNavigationView.java:83)
     at android.support.design.widget.BottomNavigationView$1.onMenuItemSelected(BottomNavigationView.java:182)
     at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:822)
     at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:171)
     at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:973)
     at android.support.design.internal.BottomNavigationMenuView$1.onClick(BottomNavigationMenuView.java:95)
     at android.view.View.performClick(View.java:6256)
     at android.view.View$PerformClick.run(View.java:24697)
     at android.os.Handler.handleCallback(Handler.java:789)
     at android.os.Handler.dispatchMessage(Handler.java:98)
     at android.os.Looper.loop(Looper.java:164)
     at android.app.ActivityThread.main(ActivityThread.java:6541)
     at java.lang.reflect.Method.invoke(Native Method)
     at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

I temporary fixed it by overriding clearItem() with a call to destroyItem() inside my custom FragmentAdapter.

@Override
public void clearItem(ViewGroup container, int position, Object object) {
    super.destroyItem(container, position, object);
}
kzotin commented 6 years ago

@Gnzlt Kudos for workaround!

hitherejoe commented 6 years ago

Thanks for pointing this out, will take a look :)