我在碎片中使用了butterknife。我有兩個兩個ViewPagers在header.xml
。 我不想用findViewById()
來實例化它們。 我試圖使用ButterKnife.bind(this,header)
,但它不允許我綁定兩次。有沒有辦法解決這個案子?如何綁定片段中的動態視圖?
(對不起我那可憐的表情,英語不是我的母語)
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View inflate = inflater.inflate(R.layout.fragment_a, null);
ButterKnife.bind(this, inflate);
View header = LayoutInflater.from(getActivity()).inflate(R.layout.header, null);
mPagerMenu = (ViewPager) header.findViewById(R.id.pager_menu);
mPagerAd = (ViewPager) header.findViewById(R.id.pager_ad);
return inflate;
}
試試這個'ButterKnife.bind(getActivity());' – Bills