Search code examples
androidfindviewbyidbutterknife

Android - replace findViewById with Butterknife


I have successfully replaced findViewByIds with Butterknife library. Unfortunately, one problem has occured:

final Button btnPopup = (Button) popupView.findViewById(R.id.btn_popup); //popupView.findViewById(...) problem!!!

How can I change this line of code in Butterknife: as Butterknife.bind(this); takes the whole activities Views


Solution

  • Bind your popupView to your main view using

    View popupView = View.inflate(getContext(), R.layout.yourPopup, null);
    ButterKnife.bind(this,popupView);
    

    Or you may want to bind it directly using

    Button btnPopup = ButterKnife.findById(popupView, R.id.btn_popup);