使用匕首2查看依赖注入

编程入门 行业动态 更新时间:2024-10-18 22:27:59
本文介绍了使用匕首2查看依赖注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个自定义视图,扩展了 TextView 。我应该在哪里调用我的组件来注入视图?

I have a custom view extending a TextView. Where should I call my component to inject the view?

component.inject(customTextView);

推荐答案

所以,我发现我需要在我的自定义视图的构造函数中添加注入(在所有这些中,或者调用另一个)

So, I've find out that I need to add the injection in the constructor of my custom view (in all of them, or make one call the other)

示例:

public class CustomTextView extends TextView { @Inject AnyProvider anyProvider; public CustomTextView(Context context) { this(context, null); } public CustomTextView(Context AttributeSet attrs) { super(context, attrs); Application.getComponent(context).inject(this); } }

更多推荐

使用匕首2查看依赖注入

本文发布于:2023-10-31 04:30:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545009.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:匕首

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!