Skip to content

动态添加数据刷新控件内容不会再崩溃了 看这。。。 #63

@ptrtony

Description

@ptrtony

动态添加数据刷新控件的时候应该对每个容器进行判断,子控件不为空应该先移除子控件再添加子控件,不然就会出现app闪退崩溃的现象,或者会出现数据叠加显示问题

代码附上:
public void setDropDownMenu(@nonnull List tabTexts, @nonnull List popupViews, @nonnull View contentView) {

    if(tabTexts.size() != popupViews.size()) {
        throw new IllegalArgumentException("params not match, tabTexts.size() should be equal popupViews.size()");
    } else {
        if (this.tabMenuView.getChildCount()>0)this.tabMenuView.removeAllViews();
        for(int i = 0; i < tabTexts.size(); ++i) {
            this.addTab(tabTexts, i);
        }

        if (this.containerView.getChildAt(0)!=null){
            this.containerView.removeViewAt(0);
        }

        this.containerView.addView(contentView, 0);
        this.maskView = new View(this.getContext());
        this.maskView.setLayoutParams(new android.widget.FrameLayout.LayoutParams(-1, -1));
        this.maskView.setBackgroundColor(this.maskColor);
        this.maskView.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
               DropDownMenu.this.closeMenu();
            }
        });

        if (this.containerView.getChildAt(1)!=null){
            this.containerView.removeViewAt(1);
        }
        this.containerView.addView(this.maskView, 1);
        this.maskView.setVisibility(8);
        if(this.containerView.getChildAt(2) != null) {
            this.containerView.removeViewAt(2);
        }

        this.popupMenuViews = new FrameLayout(this.getContext());
        this.popupMenuViews.setLayoutParams(new android.widget.FrameLayout.LayoutParams(-1, (int)((float) DisplayUtils.getScreenSize(this.getContext()).y * this.menuHeighPercent)));
        this.popupMenuViews.setVisibility(8);
        this.containerView.addView(this.popupMenuViews, 2);
        if (popupMenuViews.getChildCount()>0)popupMenuViews.removeAllViews();
        for(int i = 0; i < popupViews.size(); ++i) {
            ((View)popupViews.get(i)).setLayoutParams(new android.view.ViewGroup.LayoutParams(-1, -2));
            this.popupMenuViews.addView((View)popupViews.get(i), i);
        }

    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions