0

The code containing the error is:

public class HomeActivity extends AppCompatActivity { BottomNavigationView bottomNavigation; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home); bottomNavigation = (BottomNavigationView) findViewById(R.id.bottomNavigation); bottomNavigation.setOnNavigationItemReselectedListener(navigation); } private BottomNavigationView.OnNavigationItemReselectedListener navigation = new BottomNavigationView.OnNavigationItemReselectedListener() { @Override public boolean onNavigationItemReselected(@NonNull MenuItem item) { switch (item.getItemId()) { case R.id.home: Toast.makeText(HomeActivity.this, "HOME", Toast.LENGTH_SHORT).show(); break; case R.id.category: Toast.makeText(HomeActivity.this, "CATEGORY", Toast.LENGTH_SHORT).show(); break; } return true; } }; } 

It is possible to see the error in this screenshot.

The code shows a Toast with the text corresponding to the selected view.

1
  • 1
    onNavigationItemReselected returns void not boolean Commented Sep 7, 2020 at 5:02

2 Answers 2

1

You are using the OnNavigationItemReselectedListener listener. The method onNavigationItemReselected has to return void instead of boolean.

Maybe you are looking for BottomNavigationView.OnNavigationItemSelectedListener listener.

Sign up to request clarification or add additional context in comments.

1 Comment

yeah, i change reselected to selected and it's work....hahaha...thanks alot
0

Check your category id in menus file first. Its containing or not

2 Comments

Yes, it has in my menus
Ok pls try to change id like category to category_id

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.