【问题标题】:How to inflate a button only one time?如何只给一个按钮充气一次?
【发布时间】:2020-06-29 16:39:51
【问题描述】:

我想只使用一次inflater 创建动态按钮。我有三个按钮,我有一个加载功能。该函数在每个按钮和每次调用时调用,预建按钮出现。我希望每次单击按钮时只创建一个按钮。怎么样?

   LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    assert inflater != null;
    LinearLayout root = (LinearLayout) inflater.inflate(R.layout.analyze_company_buttons_layout, null, false);

    Button btnCompany = root.findViewById(R.id.btnCompany);
    btnCompany.setText(header);
    btnCompany.setTag(headerCode);
    btnCompany.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String compCode = (String) view.getTag();
            Company company = getCompany(compCode, filterCompanyList);
            lines = new ArrayList<>();
            if (company != null) {

                filterCompanyList.remove(company);

                setBackgroundColorForTabButton(view, lytTabs, R.color.colorPrimaryExtraExtraLight, R.color.white);

            } else {
                company = getCompany(compCode, companyList);
                filterCompanyList.add(company);
                setBackgroundColorForTabButton(view, lytTabs, R.color.white, R.color.colorPrimaryExtraExtraLight);
            }
            loadFunct(startDate, endDate, "LW");
        }
    });

    lytTabs.addView(root);
    setBackgroundColorForTabButton(btnCompany, lytTabs, R.color.white, R.color.colorPrimaryExtraExtraLight);
    lytTabs.invalidate();

【问题讨论】:

    标签: android button layout-inflater android-inflate


    【解决方案1】:

    lytTabs.removeAllViews();功能适用于它

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多