2017-08-25 61 views
3

我已經用Butterknife庫成功替換findViewByIds。 不幸的是,一個問題已經發生:Android - 用Butterknife替換findViewById

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

我怎樣才能改變這一行代碼在Butterknife:作爲Butterknife.bind(this);佔用了整個活動Views

回答

4

綁定您的popupView使用

View popupView = View.inflate(getContext(), R.layout.yourPopup, null); 
ButterKnife.bind(this,popupView); 
你的主要觀點

或者您可能希望直接使用

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

作品。謝謝。順利 – Zoffa

+0

只需要第二個。這會膨脹您的彈出視圖並找到您的按鈕的引用。您的歡迎;) –

+0

是的。我拿到了第二名。 – Zoffa

0

首先,有2周的事情,其依賴於加入到使用庫:

Buil.gradle

compile 'com.jakewharton:butterknife:8.8.1' 
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' 

然後,使用上述@BindView方法onCreate後內部的方法寫ButterKnife(this, "any other unrelated views to this layout"

「與此佈局有任何其他不相關的視圖」可以是另一個佈局的內容,例如彈出窗口或....