Open shidcordero opened 5 years ago
On first expand, the expandable layout does not show anything but after next click it will show the view.
Sample Code
` ArrayList categorySubItemModels = categoryMainItemModel.getCategorySubItemModelList(); subCategoryButtons = new ArrayList<>(); for (int i = 0; i < categorySubItemModels.size(); i++) { CategorySubItemModel categorySub = categorySubItemModels.get(i);
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); AppCompatButton button = (AppCompatButton) layoutInflater.inflate(R.layout.row_category_button_item, null); ConstraintLayout.LayoutParams lp = new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.WRAP_CONTENT, ConstraintLayout.LayoutParams.WRAP_CONTENT); int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,8,context.getResources().getDisplayMetrics()); lp.setMargins(0, 0, margin, margin); button.setLayoutParams(lp); button.setTag("tagSubButton" + i); button.setText(categorySub.getSubCategoryName()); button.setOnClickListener(v -> { clearActivatedSubCategoryBtn(); v.setActivated(true); if (categorySub.getSubSubCategoryNameList() != null){ tvSubTitle.setText(categorySub.getSubCategoryName()); flSubSubCategoryBtnContainer.removeAllViews(); subSubCategoryButtons = new ArrayList<>(); for (int x = 0; x < categorySub.getSubSubCategoryNameList().size(); x++){ String subSubCategoryName = categorySub.getSubSubCategoryNameList().get(x); LayoutInflater layoutInflaterSub = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); AppCompatButton buttonSub = (AppCompatButton) layoutInflaterSub.inflate(R.layout.row_category_button_item, null); ConstraintLayout.LayoutParams lpSub = new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.WRAP_CONTENT, ConstraintLayout.LayoutParams.WRAP_CONTENT); int marginSub = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,8,context.getResources().getDisplayMetrics()); lpSub.setMargins(0, 0, marginSub, marginSub); buttonSub.setLayoutParams(lpSub); buttonSub.setTag("tagSubSubButton" + x); buttonSub.setText(subSubCategoryName); buttonSub.setOnClickListener(v2 -> { clearActivatedSubSubCategoryBtn(); v2.setActivated(true); }); flSubSubCategoryBtnContainer.addView(buttonSub); subSubCategoryButtons.add(buttonSub); } elSubSubCategoryContainer.expand(); } }); flSubCategoryBtnContainer.addView(button); subCategoryButtons.add(button);
}`
On first expand, the expandable layout does not show anything but after next click it will show the view.
Sample Code
` ArrayList categorySubItemModels =
categoryMainItemModel.getCategorySubItemModelList();
subCategoryButtons = new ArrayList<>();
for (int i = 0; i < categorySubItemModels.size(); i++) {
CategorySubItemModel categorySub = categorySubItemModels.get(i);
}`