android - 如何只给一个按钮充气一次?
问题描述
我想只使用一次充气机创建动态按钮。我有三个按钮,我有一个加载功能。这个函数在每个按钮和每个调用时间调用,预建按钮出现。我希望每次单击按钮时只创建一个按钮。如何?
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();
解决方案
lytTabs.removeAllViews(); 功能适用于它
推荐阅读
- php - 如何创建作曲家包的测试版?
- c# - 编译器迫使我在“...”上实现终结器或析构函数
- javascript - Firebase 存储可恢复在网络上上传大文件
- mqtt - 具有负载均衡应用服务器的 MQTT
- docker - 使用通过 Docker 安装的 Jenkins 运行 AWS 命令行界面:找不到命令?
- php - json数组上的嵌套foreach循环,将索引映射到值
- ios - UIPageControl 画外音问题
- python - 更改跟踪时如何更新情节子图?
- json - 关于从 Rest Api 请求所有元素列表的问题(将 json 字符串转换为 java 对象列表)
- javascript - 未捕获的类型错误:无法在 HTMLInputElement.onclick 的 signUpValidate (fhe.js:26) 处读取 null 的属性“值”