I am using a bottom navigation bar from the below link. https://github.com/Droppers/AnimatedBottomBar#configuration

I am trying to switch/open a new fragment on clicking the buttons in the bottom navigation.

This is my code: public class HomeActivity extends AppCompatActivity {

private static final String TAG = HomeActivity.class.getSimpleName();
AnimatedBottomBar animatedBottomBar;
FragmentManager fragmentManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);

    //calling bottom navigation bar
    animatedBottomBar = findViewById(R.id.animatedBottomBar);

    //listening to click on nav bar
    animatedBottomBar.setOnTabSelectListener(new AnimatedBottomBar.OnTabSelectListener() {
        @Override
        public void onTabSelected(int lastIndex, @Nullable AnimatedBottomBar.Tab lastTab, int newIndex, @NonNull AnimatedBottomBar.Tab newTab) {
            Fragment fragment = null;
            switch (newTab.getId())
            {
                case R.id.home:
                    fragment = new HomeFragment();
                    break;
                case R.id.discover:
                    fragment = new DiscoverFragment();
                    break;
                case R.id.broadcast:
                    fragment = new BroadcastFragment();
                    break;
                case R.id.profile:
                    fragment = new ProfileFragment();
                    break;
            }
            if (fragment != null)
            {
                fragmentManager = getSupportFragmentManager();
                assert false;
                fragmentManager.beginTransaction().replace(R.id.fragment_container, fragment)
                        .commit();
            }
            else
            {
                Log.e(TAG, "Error in creating fragment");
            }
        }

        @Override
        public void onTabReselected(int i, @NonNull AnimatedBottomBar.Tab tab) {

        }
    });
}

}

The below lines are highlighted along with a warning:

R.id.home, R.id.discover, R.id.broadcast, R.id.profile

The warning:

"Resource IDs will be non-final by default in Android Gradle Plugin version 8.0, avoid using them in switch case statements".

what should i do? I am pretty new to fragments and complex codes, i mean complex for me lol, any help would be wonderful. Thanks in advance.

0

There are 0 best solutions below