chuross / expandable-layout

http://qiita.com/chuross/items/81328feff73f55f9022e
Apache License 2.0
61 stars 16 forks source link

Does not show dynamic views on first expand #5

Open shidcordero opened 5 years ago

shidcordero commented 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);

}`