首页 > 解决方案 > 充气芯片非常慢

问题描述

因此,当我创建片段时,我试图通过 Java 为芯片组中的一些芯片充气。片段位于 ViewPager 中。

一切正常,但在控制台上我可以看到 W/ResourceType: No package identifier when getting value for resource number 0x00000000 芯片组何时填充。

chipGroup 的填充速度非常慢,这会导致在交换 viewPager 的片段时“冻结”1 秒。

我在这里想念什么?我真的怀疑问题仍然存在于我为chipGroup 中的芯片充气但找不到真正原因的方式上。

.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);
        }
    }

标签: javaandroidmaterial-design

解决方案


推荐阅读