Closed Deandrew007 closed 6 years ago
You probably need to call the bottom navigation item selection method, and also fire the onClickListener
so it shows the Fragment
Here's a snippet of my code.
` bottomNavigationBar.setCurrentItem(0); bottomNavigationBar.setOnTabSelectedListener((position, wasSelected) -> {
if (position == SHOP_FRAGMENT)
{
getSupportFragmentManager().beginTransaction().replace(R.id.frame_container, new ShopFragment()).commit();
}
else if (position == MESSAGES_FRAGMENT)
{
getSupportFragmentManager().beginTransaction().replace(R.id.frame_container, new MessagesFragment()).commit();
}
else if (position == PROFILE_FRAGMENT)
{
getSupportFragmentManager().beginTransaction().replace(R.id.frame_container, new ProfileFragment()).commit();
}
return true;
});`
I haven't tested but I think putting bottomNavigationBar.setCurrentItem(0);
after setting the listener, should work.
Like so:
bottomNavigationBar.setOnTabSelectedListener((position, wasSelected) -> {
...
});
bottomNavigationBar.setCurrentItem(0);
As a suggestion, when posting multiple lines of code wrap it like this:
```java
System.out.println("Hello, World!");
```
Your solution was a fix. Thanks a lot and also for the suggestion.
Hey, lovely lib. My first fragment isn't visible unless another tab is clicked, then reselect the first tab or the first tab is clicked twice. Which is when the fragment is shown. Any possible suggestions?