Having trouble implementing RecyclerView in Fragment after saving Arryaylist into json as shared preferences

I am having trouble displaying the fragment nothing showed up in my activity. My goal is to save the sharedpreference as gson since arraylist cannot be saved into sharedpreference and then use gson to display the arraylist in recyclerview in fragments

this is from my activity where it saves the user input data into json

private void saveDataToSharedPreference(String categoryId, String categoryName, Integer eventCount, Boolean switchActivated){
    ArrayList<CategoryList> category_list = new ArrayList<CategoryList>();
    SharedPreferences preferences = getSharedPreferences("CategoryInfo",MODE_PRIVATE);

    SharedPreferences.Editor edit = getPreferences(MODE_PRIVATE).edit();
    category_list.add(new CategoryList(categoryId,categoryName,eventCount,switchActivated));
    String json = gson.toJson(category_list);

    edit.putString("category_info",json);
    edit.apply();
}

this is my fragment to display the recyclerview

   @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        myRecyclerView = view.findViewById(R.id.categoryRecyclerView);
        myRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

        layoutManager = new LinearLayoutManager(getView().getContext());
        myRecyclerView.setLayoutManager(layoutManager);
        MyRecyclerAdapter myRecyclerAdapter = new MyRecyclerAdapter(getContext(),listCategory);
        myRecyclerView.setAdapter(myRecyclerAdapter);
        myRecyclerAdapter.notifyDataSetChanged();

    }

this is my recycler adapter

public class MyRecyclerAdapter extends RecyclerView.Adapter<MyRecyclerAdapter.CustomViewHolder>{

    Context context;
    ArrayList<CategoryList> categoryArrayList = new ArrayList<CategoryList>();

    public MyRecyclerAdapter(Context context,ArrayList<CategoryList> categoryArrayList){
        this.context = context;
        this.categoryArrayList = categoryArrayList;
    }


    @NonNull
    @Override
    public CustomViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.category_card_layout, parent, false);
        return new CustomViewHolder(v);
    }

    @Override
    public void onBindViewHolder(@NonNull CustomViewHolder holder, int position) {
        holder.tvCategoryId.setText(categoryArrayList.get(position).getCat_id());
        holder.tvCategoryName.setText(categoryArrayList.get(position).getCat_name());
        holder.tvEventCount.setText(String.valueOf(categoryArrayList.get(position).getEvent_count()));
        if (categoryArrayList.get(position).getIs_active()){
            holder.tvIsActive.setText("Yes");
        } else {
            holder.tvIsActive.setText("No");
        }
    }

    @Override
    public int getItemCount() {
        return categoryArrayList.size();
    }

    public static class CustomViewHolder extends RecyclerView.ViewHolder {

        public TextView tvCategoryId;
        public TextView tvCategoryName;
        public TextView tvEventCount;
        public TextView tvIsActive;

        public CustomViewHolder(@NonNull View itemView) {
            super(itemView);
            tvCategoryId = itemView.findViewById(R.id.tv_id);
            tvCategoryName = itemView.findViewById(R.id.tv_name);
            tvEventCount = itemView.findViewById(R.id.tv_eventcount);
            tvIsActive = itemView.findViewById(R.id.tv_active);
        }
    }
}

I logged the json file and its saving properly as it shows:
[{“cat_id”:”CFO-6328″,”cat_name”:”hello”,”event_count”:231,”is_active”:false}]
at logcat so I am confused about what should I do get the fragments to show in my activity

New contributor

Inu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật