Reputation: 1009
I have a bottom navigation bar, I don't know why, but I need to click it 2 times before executing the task.
This is the xml for bottom navigation
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemBackground="@color/colorPrimary"
app:itemIconTint="@color/white"
app:itemTextColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
android:focusableInTouchMode="true"
app:menu="@menu/bottom_navigation_admin" />
This is how I call it on activity
private void setBottomNavigation() {
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation_view);
bottomNavigationView.setOnNavigationItemReselectedListener(new BottomNavigationView.OnNavigationItemReselectedListener() {
@Override
public void onNavigationItemReselected(@NonNull MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.navigation_override :
fragment = new OverrideFragment();
fragmentManager.beginTransaction().replace(R.id.fragment_layout, fragment).commit();
break;
case R.id.navigation_user:
fragment = new UserListFragment();
fragmentManager.beginTransaction().replace(R.id.fragment_layout, fragment).commit();
break;
case R.id.navigation_log_out:
CustomDialog customDialog = new CustomDialog(AdminBoardActivity.this);
customDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
customDialog.show();
break;
}
}
});
}
Upvotes: 0
Views: 719
Reputation: 1195
you are using setOnNavigationItemReselectedListener
use this
setOnNavigationItemSelectedListener
Upvotes: 0
Reputation: 773
You are setting a reselect listener but you need to set onitem select listener. replace
bottomNavigationView.setOnNavigationItemReselectedListener()
with
BottomNavigationView.OnNavigationItemSelectedListener()
Upvotes: 0
Reputation: 1431
You use
bottomNavigationView.setOnNavigationItemReselectedListener instead of
bottomNavigationView.setOnNavigationItemSelectedListener
not Reselected only Selected ;)
Upvotes: 4