我有一个适配器,它扩展了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