领券联盟 :已经获取到具体的分类数据,但homeFragment(子fragment)显示出错
已经获取到具体的分类数据,但homeFragment显示的却是base_fragment_layout.xml页面
public class homeFragment extends BaseFragment implements ICategoryPagerCallback {
private ICategotyPagerPresenter categoryPagePresenter;
private int materialId;
@BindView(R.id.home_pager_list)
public RecyclerView mContentList;
private HomePageContentAdapter mContentAdapter;
@Override
protected int initlayout() {
return R.layout.fragment_home_pager;
}
public static homeFragment newInstance (Category.DataBean category){
homeFragment mHomeFragment = new homeFragment();
Bundle bundle = new Bundle();
bundle.putString(Constant.KEY_HOME_PAGER_TITLE,category.getTitle());
bundle.putInt(Constant.KEY_HOME_PAGER_MATERIAL_ID,category.getId());
mHomeFragment.setArguments(bundle);
return mHomeFragment;
}
@Override
protected void initPresenter() {
categoryPagePresenter = CategoryPagePresenterImpl.getInstance();
categoryPagePresenter.registerCallback(this);
}
protected void initView(View rootView) {
mContentList.setLayoutManager(new LinearLayoutManager(getContext()));
mContentList.addItemDecoration(new RecyclerView.ItemDecoration() {
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
outRect.top = 8;
outRect.bottom = 8;
}
});
mContentAdapter = new HomePageContentAdapter();
mContentList.setAdapter(mContentAdapter);
}
protected void loadData() {
Bundle arguments = getArguments();
String title = arguments.getString(Constant.KEY_HOME_PAGER_TITLE);
materialId = arguments.getInt(Constant.KEY_HOME_PAGER_MATERIAL_ID);
Log.i("title", "" + title);
Log.i("id", "" + materialId);
if (categoryPagePresenter != null) {
categoryPagePresenter.getContentByCategoryId(materialId);
}
}
@Override
public void onContentLoaded(List<HomePagerContent.DataBean> contents) {
setUpState(State.SUCCESS );
mContentAdapter.setData(contents);
}
@Override
public int getCategotyId() {
return materialId;
}
@Override
public void onLoading() {
setUpState(State.LOADING);
}
@Override
public void onError() {
setUpState(State.ERROR);
}
@Override
public void onEmpty() {
setUpState(State.EMPTY);
}
@Override
public void onLoaderMoreError() {
}
@Override
public void onLoaderMoreEmpty() {
}
@Override
public void onLoaderMoreLoaded(List<HomePagerContent.DataBean> contents) {
}
@Override
public void onLooperListLoaded(List<HomePagerContent.DataBean> contents) {
}
protected void release() {
if (categoryPagePresenter != null) {
categoryPagePresenter.unregisterCallback(this);
}
}
base_fragment_layout.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/base_container"
>
但homeFragment显示的却是base_fragment_layout.xml页面
这问题不就很简单了吗?你自己都说了,显示的是base_fragment_layout的布局
为什么没有显示子类的布局呢?
那我再问你,凭什么显示子类的布局呢?
R.layout.fragment_home_pager;你这个布局是不是跟base_fragment_layout的布局一样,如果你复制粘贴的话。
是不是没有覆盖相关的方法,所以没法载入子类的布局。
跟一下流程就完事了。这么简单。