это мой код для Показать элементы категории:
public class CategoryFragmentBehavior extends FragmentBehavior {
protected RecyclerView recyclerView;
protected RVOutCategoryAdapter rvOutCategoryAdapter;
protected int index;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
bundle = getArguments();
return inflater.inflate(R.layout.tab_cat_1, container, false);
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
init();
}
protected void init() {
super.init();
recyclerView = (RecyclerView) activity.findViewById(R.id.rv);
TabHome.btnCountRV.setVisibility(View.GONE);
id = bundle.getInt(Variables.CART_ID);
TabHome.setTvBreadcrumbs(bundle.getString(Variables.CART_TITLE), index);
}
}
На первой вкладке категории материал отображается хорошо. это мой код на первой вкладке:
public class TabCat1 extends CategoryFragmentBehavior {
private List<HiModel.CategoryParent> categorySub1ListBeen;
public static TabCat1 newInstance() {
TabCat1 fragment = new TabCat1();
return fragment;
}
protected void init() {
index = 0;
super.init();
categorySub1ListBeen = GlobalVariable.newInstance().getHiModel().getCategorySub1List();
categorySub1ListBeen = ToolsBehavior.getFilterList(id, categorySub1ListBeen);
if (categorySub1ListBeen.size() > 0)
initRVOutCategory();
else
showWallDialog(getString(R.string.coming_soon), R.drawable.ic_folder_open_blue_50_48dp);
}
private void initRVOutCategory() {
rvOutCategoryAdapter = new RVOutCategoryAdapter(activity, categorySub1ListBeen, new RVOutCategoryAdapter.CallBack() {
@Override
public void onItemClick(int position, View view) {
HiModel.CategoryParent categoryParent = categorySub1ListBeen.get(position);
TabHome.TabController(categoryParent, index);
}
});
recyclerView.setLayoutManager(new LinearLayoutManager(activity));
recyclerView.setAdapter(rvOutCategoryAdapter);
}
@Override
public void onDestroy() {
super.onDestroy();
TabHome.setTvBreadcrumbs("", 0);
}
}
Когда я нажимаю на элемент, отображается вторая вкладка, но элементы не отображаются. это мой код на второй вкладке:
public class TabCat2 extends CategoryFragmentBehavior {
private List<HiModel.CategoryParent> categorySub2ListBeen;
public static TabCat2 newInstance() {
TabCat2 fragment = new TabCat2();
return fragment;
}
protected void init() {
index = 1;
super.init();
categorySub2ListBeen = GlobalVariable.newInstance().getHiModel().getCategorySub2List();
categorySub2ListBeen = ToolsBehavior.getFilterList(id, categorySub2ListBeen);
if (categorySub2ListBeen.size() > 0)
initRVOutCategory();
else
showWallDialog(getString(R.string.coming_soon), R.drawable.ic_folder_open_blue_50_48dp);
}
private void initRVOutCategory() {
rvOutCategoryAdapter = new RVOutCategoryAdapter(activity,categorySub2ListBeen, new RVOutCategoryAdapter.CallBack() {
@Override
public void onItemClick(int position, View view) {
HiModel.CategoryParent categoryParent = categorySub2ListBeen.get(position);
TabHome.TabController(categoryParent, index);
}
});
recyclerView.setLayoutManager(new LinearLayoutManager(activity));
recyclerView.setAdapter(rvOutCategoryAdapter);
}
}
это мой адаптер Код:
public class RVOutCategoryAdapter extends RecyclerView.Adapter<RVOutCategoryAdapter.MyViewHolder> {
private Context mContext;
private List<HiModel.CategoryParent> categoryParents;
private CallBack callBack;
public interface CallBack {
void onItemClick(int position, View view);
}
public class MyViewHolder extends RecyclerView.ViewHolder {
protected TextView tvTitle;
public MyViewHolder(final View view) {
super(view);
tvTitle = (TextView) view.findViewById(R.id.tv);
}
}
public RVOutCategoryAdapter(Context mContext, List<HiModel.CategoryParent> categoryParents, CallBack callBack) {
this.mContext = mContext;
this.callBack = callBack;
this.categoryParents = categoryParents;
}
public void setmContext(Context mContext) {
this.mContext = mContext;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_out_category, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(MyViewHolder holder, final int position) {
HiModel.CategoryParent categorySub1ListBean = categoryParents.get(position);
holder.setIsRecyclable(false);
holder.tvTitle.setText(categorySub1ListBean.getName());
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
callBack.onItemClick(position, v);
}
});
}
@Override
public int getItemCount() {
return categoryParents.size();
}
public void clear() {
final int size = categoryParents.size();
categoryParents.clear();
notifyItemRangeRemoved(0, size);
}
}
на Android 7 и ниже, элементы на второй вкладке отображаются хорошо , но не в Android 8. И выдает следующую ошибку:
RecyclerView: No adapter attached; skipping layout
Пожалуйста, помогите мне Спасибо