Inflating Chips very slow

2

So, I'm trying to inflate some chips in a chipGroup via Java when I am creating a fragment. The fragments are inside a ViewPager.

Everything works fine but on the console I can see W/ResourceType: No package identifier when getting value for resource number 0x00000000 when the chipGroup is populated.

The population of the chipGroup is very slow, this cause a "freeze" of 1sec when swapping fragments of the viewPager.

What am I missing here? I really suspect the problem stay in the way I inflate the chips in the chipGroup but can't find the real cause.

.xml ...

    <com.google.android.material.chip.ChipGroup
        android:id="@+id/chipGroup_variants"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        app:singleLine="false"
        app:singleSelection="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

.java ...

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        super.onCreateView(inflater,container,savedInstanceState);

        //retrieve categoryDto when coming back from rotate
        if(savedInstanceState != null)
            categoryDTO = (CategoryDTO)savedInstanceState.getSerializable(FRAGMENT_NAME);

        View view = inflater.inflate(R.layout.fragment_category,container,false);

        RecyclerView recyclerView =  (RecyclerView) view.findViewById(R.id.recycler_view_category_elements);

        ProductAdapter productAdapter = new ProductAdapter(view.getContext(), categoryDTO.getOnlyActiveProductDTOS());
        productAdapter.setCallerFragment(this);
        recyclerView.setAdapter(productAdapter);

        GridLayoutManager manager = new GridLayoutManager(view.getContext(), 3, RecyclerView.VERTICAL, false);
        recyclerView.setLayoutManager(manager);

        ticketViewModel = ViewModelProviders.of(getActivity()).get(TicketViewModel.class);

        //create chips
        buildVariantChipGroup(view, categoryDTO.getCategoryVariantDTOS());

        this.view = view;
        return view;
    }

    private void buildVariantChipGroup(View view, List<CategoryVariantDTO> variantDTOList)
    {
        ChipGroup chipGroup = view.findViewById(R.id.chipGroup_variants);

        for(CategoryVariantDTO variantDTO : variantDTOList)
        {
            final Chip chip = new Chip(this.getContext());
            chip.setText(variantDTO.getName()+ (variantDTO.getPrice() == 0 ? "": ActivityUtils.formatPriceDouble(variantDTO.getPrice())));
            chip.setTextSize(30);
            chip.setOnClickListener(v -> ticketViewModel.addVariantToLastTicketRow(variantDTO));
            chipGroup.addView(chip);
        }
    }
java
android
material-design
asked on Stack Overflow Jul 13, 2019 by Nkp

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0