gpt4 book ai didi

java - 不推荐使用 setOnNavigationItemSelectedListener

转载 作者:行者123 更新时间:2023-12-04 23:35:42 24 4
gpt4 key购买 nike

目前我正在开发一个底部导航栏和三个菜单项的应用程序。我用过setOnNavigationItemSelectedListener()对于被点击的项目。但现在我面临该方法已贬值的问题。

  • 应用语言:Java
  • 问题:'setOnNavigationItemSelectedListener(com.google.android.material.bottomnavigation.BottomNavigationView.OnNavigationItemSelectedListener)' is deprecated

  • 有什么办法可以解决吗?有没有比 setOnNavigationItemSelectedListener() 更好的选择?方法。

    最佳答案

    根据 github 来源已弃用它:BottomNavigationView.setOnNavigationItemSelectedListener
    在其评论中,您可以阅读:

    @deprecated Use {@link NavigationBarView#setOnItemSelectedListener(OnItemSelectedListener)}
    * instead.
    所以使用 NavigationBarView.setOnItemSelectedListener从它的基类:
      /**
    * Set a listener that will be notified when a navigation item is selected. This listener will
    * also be notified when the currently selected item is reselected, unless an {@link
    * OnItemReselectedListener} has also been set.
    *
    * @param listener The listener to notify
    * @see #setOnItemReselectedListener(OnItemReselectedListener)
    */
    public void setOnItemSelectedListener(@Nullable OnItemSelectedListener listener) {
    selectedListener = listener;
    }
    另见 commit
    因为它解释了对这种变化的困惑:

    The listeners were deprecated in favor ofNavigationBarView#OnItemSelectedListener andNavigationBarView#OnItemReselectedListener, but deprecationdocumentation was never added, so it's unclear what developers shoulduse instead.

    关于java - 不推荐使用 setOnNavigationItemSelectedListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68021770/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com