As the title says, I have a BottomNavigationView
with 3 Menu Items and want to assign a long click listener to each of them.
I have set an OnNavigationItemSelectedListener
on the BottoNavigationView
.
I have tried this answer
here
but that did not work out for me...
Any other way you guys recommend?
This is what I have...Regular clicks work btw
private void setUpNavigationListeners() {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.fragment_container, new CalendarView()).commit();
navigation.setOnNavigationItemSelectedListener(
new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Fragment fragment;
switch (item.getItemId()) {
case R.id.navigation_courses:
subtitle.setText(R.string.courses);
fragment = new CalendarView();
break;
case R.id.navigation_assignments:
subtitle.setText(R.string.assignments);
fragment = new AssignmentView();
break;
case R.id.navigation_professors:
subtitle.setText(R.string.professors);
return false;
default:
return false;
}
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.replace(R.id.fragment_container, fragment).commit();
return true;
}
});
navigation.setItemIconTintList(null);
Menu menu = navigation.getMenu();
MenuItem courses = menu.findItem(R.id.navigation_courses);
MenuItem assignments = menu.findItem(R.id.navigation_assignments);
MenuItem prof = menu.findItem(R.id.navigation_professors);
courses.setActionView(new ImageButton(this));
courses.getActionView().setLongClickable(true);
Log.d("Manage", "Is long clickable:" + courses.getActionView().isLongClickable());
courses.getActionView().setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Log.d("Manage", "Long clicked");
return true;
}
});
}