因此,当我创建片段时,我试图通过Java为chipGroup中的一些芯片充气。片段位于ViewPager中。
一切正常,但在控制台上我可以看到
W/ResourceType: No package identifier when getting value for resource number 0x00000000
填充chipGroup时。
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);
}
}