private void SelectedItem() {
NavigationBarView navigationBarView = findViewById(R.id.bottom_navigation);
navigationBarView.setOnItemSelectedListener(new NavigationBarView.OnItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.item_1:
// Handle item_1 selection
return true; // Return true if you've handled the selection.
case R.id.item_2:
// Handle item_2 selection
return true; // Return true if you've handled the selection.
default:
return false; // Return false for unhandled selections.
}
}
});
}
new NavigationBarView.OnItemSelectedListener((AdapterView<?> parent, View view, int position, long id) -> {
switch (parent.getId()) {
case R.id.item_1:
return true;
case R.id.item_2:
return true;
default:
return false;
}
});
Referring in Java, I tried using both the lambda expression and the overriding method, but no matter what I've tried it doesn't work. Yes, I've tried Kotlin and it works but i want to use java for my project base entirely.
I cannot override the SetOnItemSelectedListener referring to both the methods i've tried.
Can anyone explain how i can either use override method or lambda expression correctly?
It either gives me getItemId()/getId() error or "R.id.item_1" error.