在导航视图菜单中设置标题在放大布局时不会起作用

时间:2018-02-21 22:17:20

标签: android menu navigation-drawer

为什么我在我的CandidateListAdapter.java中设置导航视图菜单的标题?但是在我的MainActivity.java中,代码完全正常

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");

1 个答案:

答案 0 :(得分:0)

要从适配器访问Activity UI元素..您可以使用interface ..然后您必须将其传递给适配器 ...点击此链接

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

更新

制作YourActivity的navView字段变量并从接口方法更改标题...将接口方法传递给changeTitle(String title);之类的标题,并在适配器中调用它: - interface.changeTitle("Maria");