java - 充气芯片非常慢
问题描述
因此,当我创建片段时,我试图通过 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);
}
}
解决方案
推荐阅读
- java - 从 2 开始打印素数到输入的数字并避免“n/2”逻辑
- javascript - React Remove Bootstrap 按钮轮廓
- c# - linq抓取点的左上角,不包括第一行第一列
- algorithm - 感染者发现算法
- python - 如何嗅探数据包,修改然后发送
- mysql - MySQL/MariaDB JSON_EXTRACT 和 JSON_CONTAINS
- django - 未使用 ManyToManyField 定义的模型
- c# - 使用 XMLDocument C# xml 添加多个节点
- spring - Spring / JPA:保存具有关联实体的实体
- eclipse-scout - Eclipse Scout 用户登录