我有一個適配器,它擴展了ArrayAdapter<T>
並且想要注入到它們中LayoutInflater
。下面的代碼提交,但吹氣總是null
Roboguice注入適配器
public abstract class MyAdapter<T> extends ArrayAdapter<T> {
@Inject
protected LayoutInflater inflater;
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// inflater here is null
}
}
是我創造我的適配器實例與'new'因爲我應該把參數傳遞到構造函數。我如何將它注入活動?我如何選擇需要的構造函數並將參數傳遞給它? –
將args傳入構造函數:http://stackoverflow.com/questions/9237996/pass-parameter-to-constructor-with-guice 或'injectMembers':http://stackoverflow.com/questions/5116383/guice- injectmembers-method 這兩種解決方案在你的情況是醜陋的:) – pawelzieba