Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在custiom视图中使用Roboguice ViewInjection。_Android_Android Fragments_Roboguice - Fatal编程技术网

Android 在custiom视图中使用Roboguice ViewInjection。

Android 在custiom视图中使用Roboguice ViewInjection。,android,android-fragments,roboguice,Android,Android Fragments,Roboguice,我有一个问题: 我创建了片段,然后用TranactionManager.replace()将其添加到活动中 A该点创建所有ok FragmentView,并注入所有视图 但接下来: public class ViewWithViews extends LinearLayout implements View.OnClickListener { @InjectView(R.id.child_text) TextView textView; private View butt

我有一个问题:

我创建了片段,然后用TranactionManager.replace()将其添加到活动中

A该点创建所有ok FragmentView,并注入所有视图

但接下来:

public class ViewWithViews extends LinearLayout implements View.OnClickListener {
    @InjectView(R.id.child_text)
    TextView textView;
    private View button;

    @Inject
    private SharedPreferences sharedPreferences;

    public ViewWithViews(Context context) {
       super(context);
       init();
       onFinishInflate();
    }

    private void init() {
        inflate(getContext(), R.layout.child_view, this);
    }

    public ViewWithViews(Context context, AttributeSet attrs) {
       super(context, attrs);
       init();
    }

    public ViewWithViews(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate(); // sharedPreferences are injected!
        this.button = findViewById(R.id.button);
        this.button.setOnClickListener(this);
        RoboGuice.injectMembers(getContext(), this); //force injection
        //still no views injected there

    }

    @Override
    public void onClick(View view) {
        System.out.println(view); // all possible events are passed, manual click. "textView" is not injected
    }
} 
ViewWithViews中没有注入视图

但是,如果将片段直接放入MainActivity R.layout.activity\u main,则会执行所有视图注入!我有点失望。是虫子,还是我做错了

org.roboguice:roboguice:3.0-alpha-2


android sdk 19

在onfinishflate调用中:

RoboGuice.getInjector(context).injectViewMembers(this);

injectMembers只调用guice注入的对象,而不是android视图。

getSupportFragmentManager().beginTransaction().replace(R.id.main_fragment,new ReaderFragment(),“fragment”).commit()

RoboGuice.getInjector(context).injectViewMembers(this);