There is a class, such as helper, for the side menu, inside the MaterialDrawer library is used

 public class NavigationDrawer { private Drawer drawer; @BindView(R.id.drawer_footer_logo) ImageView footerLogo; @OnClick(R.id.drawer_footer_logo) public void onFooterLogoClick() { close(): if(drawerListener != null) { drawerListener.onFooterLogoClick(); } } public NavigationDrawer(Activity activity) { drawer = new DrawerBuilder() .withActivity(activity) .withHeader(R.layout.drawer_header) .withFooter(R.layout.drawer_footer) //etc.. .build(); ButterKnife.bind(this, drawer.getDrawerLayout()); } public void close() { drawer.close(); } //etc.. } 

When you click on the logo, nothing happens (the side menu should close). If I change @OnClick to setOnClickListener after ButterKnife.bind , then the application drops to NPE. What's wrong?

  • IMHO, ButterKnife is good for AAA, in MV-like architectures - NO, that’s a living example, I ButterKnife into a separate class and ButterKnife powerless - Flippy
  • one
    It is very strange to blame libraries, in particular cases, especially in architectures, what is AAA? MV structure? If you mean the Model View, then they are all very different, oh yes - this does not show a living example and the problem was not solved in this. - Shwarz Andrei
  • @Shwarz Andrei, yes, sorry, I got excited) - Flippy
  • But minus then why? - Barmaley

1 answer 1

IMHO you are trying to bind the wrong content.

Try:

 ButterKnife.bind(this, drawer.getContent()); 

PS As the author warns ButterKnife:

Butter dagger only infinitely less sharp.

Well, that is roughly speaking - be careful, do not get hurt :)

  • getContent returns the root View in which DrawerLayout ? - Flippy
  • It returns the FrameLayout inside which the remaining views are placed - Barmaley
  • It did not help, the same NPE - Flippy