如果在Fragment中没有@Inject构造函数,则无法提供LinearLayoutManager

时间:2019-01-08 21:55:58

标签: android android-fragments dependency-injection dagger-2 mvp

我正在使用Dagger 2,并且在创建新片段时似乎出现此错误。我一直在尝试各种方法,但我根本无法修复此消息。

如果没有@Inject构造函数,则无法提供

android.support.v7.widget.LinearLayoutManager

如果我正在引用Mindorks MVP Project on Github,似乎应该很简单。

这是我的Fragments代码,如果需要或显而易见的话,请告诉我。

public class HomePageFragment extends BaseFragment implements
    HomeMvpView {

@Inject
HomeMvpPresenter<HomeMvpView> mPresenter;

@BindView(R.id.featuredRecyclerView)
RecyclerView featuredRecyclerView;

@Inject
LinearLayoutManager mLayoutManager;

@Inject
RecyclerView.LayoutManager mLayoutManager2;

@Inject
FeaturedAdapter featuredAdapter;

public static HomePageFragment newInstance() {
    Bundle args = new Bundle();
    HomePageFragment fragment = new HomePageFragment();
    fragment.setArguments(args);
    return fragment;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_home_page, container, false);

    ActivityComponent component = getActivityComponent();

    if (component != null) {
        component.inject(this);
        setUnBinder(ButterKnife.bind(this, rootView));

        mPresenter.onAttach(this);

    }
    return rootView;
}


@Override
protected void setUp(View view) {
    featuredRecyclerView = view.findViewById(R.id.featuredRecyclerView);

    //setup Adapter
    mLayoutManager2 = new LinearLayoutManager(getActivity());
    //mLayoutManager2.setOrientation(LinearLayoutManager.VERTICAL);
    featuredRecyclerView.setLayoutManager(mLayoutManager);
    featuredRecyclerView.setItemAnimator(new DefaultItemAnimator());
    featuredRecyclerView.setAdapter(featuredAdapter);
}
}

0 个答案:

没有答案