what is this reminder that RecyclerView can"t find it? I have three classes here, SystemMessageFragment extends LazyFragment extends BaseFragment. in turn. Here is the error log and three classes
SystemMessageFragment
public class SystemMessageFragment extends LazyFragment {
@BindView(R.id.rv_message_system)
RecyclerView mRecyclerView;
private List<String> mDatas;
private SystemMessageAdapter mAdapter;
@Override
public int contentViewId() {
return R.layout.fragment_system_message;
}
@Override
public void initView(Bundle savedInstanceState, View view) {
// ButterKnife.bind(this,view);
}
@Override
protected void onLazyLoad() {
mDatas = new ArrayList<>();
for (int i = 0; i < 5; iPP) {
mDatas.add("" + i);
}
mAdapter = new SystemMessageAdapter(R.layout.item_message_system, mDatas);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(linearLayoutManager);
mRecyclerView.setAdapter(mAdapter);
}
}
LazyFragment:
public abstract class LazyFragment extends BaseFragment {
private boolean isInit = false;
private View mContainerView;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//
if (getUserVisibleHint() && !isInit) {
mContainerView = super.onCreateView(inflater, container, savedInstanceState);
isInit = true;
} else {
//
mContainerView = inflater.inflate(R.layout.lazy_loading, container, false);
mContainerView.setBackgroundColor(lazyFragmentBackground());
}
return mContainerView;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
if (!getUserVisibleHint() && !isInit) {
return;
}
super.onViewCreated(view, savedInstanceState);
if (isInit) {
onLazyLoad();
}
}
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isAdded()) { //
//
if (isVisibleToUser && !isInit && mContainerView != null) {
if (mContainerView instanceof ViewGroup) { //viewgroupview
ViewGroup group = ((ViewGroup) mContainerView);
group.removeAllViews();
View view = LayoutInflater.from(getActivity()).inflate(contentViewId(), group, false);
group.addView(view);
super.onViewCreated(mContainerView, null);
onLazyLoad();
isInit = true;
}
}
if (isInit && mContainerView != null) { //
if (isVisibleToUser) {
onShowFragment();
} else {
onHideFragment();
}
}
}
}
protected abstract void onLazyLoad();
protected int lazyFragmentBackground() {
return ContextCompat.getColor(getActivity(), R.color.lazy_fragment_background);
}
protected void onShowFragment() {
}
protected void onHideFragment() {
}
@Override
public void onDetach() {
super.onDetach();
isInit = false;
}
}
BaseFragment:
public abstract class BaseFragment extends Fragment {
private Unbinder mUnbinder;
private TextView mTitleTv;
private TextView mLeftMenuTv;
private TextView mRightMenuTv;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(contentViewId(), container, false);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// EventBusUtil.register(this);
mUnbinder = ButterKnife.bind(this, view);
// View toolbar = view.findViewById(R.id.toolbar);
// if (toolbar != null) {
// mTitleTv = toolbar.findViewById(R.id.title_tv);
// mLeftMenuTv = toolbar.findViewById(R.id.left_menu_tv);
// mRightMenuTv = toolbar.findViewById(R.id.right_menu_tv);
// int height = StatusBarUtil.getStatusBarHeight(getActivity());
// ViewGroup.LayoutParams viewGroup = toolbar.getLayoutParams();
// viewGroup.height = getResources().getDimensionPixelSize(R.dimen.titlebar_height) + height;
// toolbar.setPadding(toolbar.getPaddingLeft(), height,
// toolbar.getPaddingRight(), toolbar.getPaddingBottom());
// toolbar.setPadding(0, height, 0, 0);
// }
initView(savedInstanceState, view);
initEvent();
}
public abstract void initView(Bundle savedInstanceState, View view);
public void initEvent() {
}
public abstract int contentViewId();
protected void setLeftMenu(String leftMenuText) {
if (mLeftMenuTv != null) {
mLeftMenuTv.setText(leftMenuText);
}
}
protected void setCenterTitle(String title) {
if (mTitleTv != null) {
mTitleTv.setText(title);
}
}
protected void setRightMenu(String rightMenuText) {
if (mRightMenuTv != null) {
mRightMenuTv.setText(rightMenuText);
}
}
protected void setLeftVisiable(boolean visiable) {
if (mLeftMenuTv != null) {
mLeftMenuTv.setVisibility(visiable ? View.VISIBLE : View.GONE);
}
}
protected void seRightVisiable(boolean visiable) {
if (mRightMenuTv != null) {
mRightMenuTv.setVisibility(visiable ? View.VISIBLE : View.GONE);
}
}
@Override
public void onDestroy() {
super.onDestroy();
if (mUnbinder != null) {
mUnbinder.unbind();
mUnbinder = null;//
}
// EventBusUtil.unregister(this);
}}