I've seen many articles how to implement bottom navigation view, but none of those solutions looked like one from new project created with Bottom Navigation Activity:
BottomNavigationView navView = findViewById(R.id.nav_view);
AppBarConfiguration.Builder(
R.id.navigation_timer, R.id.navigation_presets)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
NavigationUI.setupWithNavController(navView, navController);
There are no transactions, no FragmentManager
etc.
Reason I'm asking is because I'm trying to implement button on Fragment2 (PresetsFragment), which after click sets values and switches view to Fragment1 (TimerFragment). This is implementation of interface in MainActivity:
@Override
public void updateCountdowns(final int round_time, final int break_time)
{
TimerFragment timer = (TimerFragment)getSupportFragmentManager().findFragmentById(R.id.navigation_timer);
if (timer != null) {
timer.updateCountdowns(round_time, break_time);
} else
{
TimerFragment new_timer = new TimerFragment();
Bundle args = new Bundle();
args.putInt("round_time_bundle", round_time);
args.putInt("break_time_bundle", break_time);
new_timer.setArguments(args);
FragmentManager fm = getSupportFragmentManager();
fm.beginTransaction()
.replace(R.id.navigation_presets, new_timer, "new_timer")
.addToBackStack(null)
.commit();
}
}
After adding logs I can see that interface works and new `TimerFragment' is created - but fragment itself doesn't change.