0

I'm working on this code

private void setupViews(){
    frameLayout = (FrameLayout) findViewById(R.id.frame_id);
    bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_nav_id);
    getSupportFragmentManager().beginTransaction().replace(R.id.frame_id,new ProfileFragment()).commit();
}

@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
    int navID = menuItem.getItemId();
    switch (navID){
        case R.id.home:
            getSupportFragmentManager().beginTransaction().replace(R.id.frame_id,new HomeFragment()).commit();
            break;
        case R.id.search:
            getSupportFragmentManager().beginTransaction().replace(R.id.frame_id,new SearchFragment()).commit();
            break;
        case R.id.profile:
            getSupportFragmentManager().beginTransaction().replace(R.id.frame_id,new ProfileFragment()).commit();
            break;
    }
    return true;
}

When I launch my app, it's automatically going on first bottom (I have 3 bottoms) I want to change this to second bottom in navigation view. Please help me

ChrisMcJava
  • 2,145
  • 5
  • 25
  • 33
  • "it's automatically going on first bottom (I have 3 bottoms)" When you say "bottom" what are you referring to? It looks like your code is trying to go the the `ProfileFragment` on startup. Is this what you want? – ChrisMcJava Apr 02 '20 at 02:07
  • Where are you calling `setupViews()`? – ianhanniballake Apr 02 '20 at 02:09
  • See my answers here: https://stackoverflow.com/questions/60536213/kotlin-first-item-in-bottomnavigationbar-isnt-visible-title-issues/60539233#60539233 – MMG Apr 02 '20 at 02:24

2 Answers2

0

@iamhanniballake

I call setupViews() in main activity I have 3 botoms -1-2-3- when my app running open fragment with a bottomnav view its automatically selected 3 I want to change it to 2

0

Try this:

bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_nav_id);
bottomNavigationView.setSelectedItemId(R.id.search);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_id,new SearchFragment()).commit();
Kasım Özdemir
  • 5,414
  • 3
  • 18
  • 35