0

Why can't I set the title of the navigation view menu in my CandidateListAdapter.java when I inflate it? But in my MainActivity.java the code works perfectly fine

MainActivity.java

NavigationView navView = (NavigationView) findViewById(R.id.right_nav_view);
    Menu menu = navView.getMenu();
    MenuItem logout = menu.findItem(R.id.nav_logout);
    logout.setTitle("asd");

CandidateListAdapter.java

inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    nav = inflater.inflate(R.layout.drawer_layout, null, false);
    NavigationView navView = (NavigationView) nav.findViewById(R.id.right_nav_view);
    Menu menu = navView.getMenu();
    MenuItem pres = menu.findItem(R.id.pres);
    pres.setTitle("Maria");
Zal Dee
  • 13
  • 4

1 Answers1

0

To access the Activity UI elements from the adapter.. you can use interface..and then you have to pass it to the adapter ...follow this link

How to get the List size() from adapter and update Activity UI from recycler Adapter itself?

Update

make the navView field variable of YourActivity and change the title from the interface method... pass the interface method a title like changeTitle(String title); and call it in adapter like :- interface.changeTitle("Maria");

Santanu Sur
  • 10,997
  • 7
  • 33
  • 52