Why can't ButterKnife bind fields that are in private inner classes?

In the fragment, I have a button that opens PopupWindow.

private class onMenuClickListener implements View.OnClickListener {
    @BindView(R.id.popup_radiogroup) RadioGroup popupRadioGroup;
    @BindView(R.id.popup_textview) TextView popupTextView;

    PopupWindow popupWindow = getPopupWindow(R.layout.popup_window);

    @Override
    public void onClick(View v) {
        ButterKnife.bind(this, popupWindow.getContentView());
        popupWindow.showAsDropDown(menuButton);
    }
}
private PopupWindow getPopupWindow(int layout_resource_id)  {
    LayoutInflater inflater = (LayoutInflater) getContext()
            .getSystemService(LAYOUT_INFLATER_SERVICE);
    View popupView = inflater.inflate(layout_resource_id,(ViewGroup)getView());

    return new PopupWindow(popupView,
            LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT,true);
}

When I try to run this code, I get this error: "@BindView fields may not be contained in private classes." Why can't ButterKnife access private inner classes, but can it freely access protected ones?

+4
source share
1 answer

, . ButterKnife , , . , ButterKnife.bind(this), this Activity, ButterKnife findViewById , , ( java).

+6

Source: https://habr.com/ru/post/1659844/


All Articles