如何在其自己的 onClick 方法中删除按钮?
我想在单击按钮后在他自己的 onClick 方法中删除按钮。我用正常的方式尝试了一下: layout.removeView(保存); 但按钮不会被删除,我也没有收到任何错误。如果我想添加按钮,我会收到错误,因为该按钮已经存在。
我认为它不起作用,因为我尝试在 OnClickHandler 处于活动状态期间删除该按钮。所以我的问题是点击按钮后如何删除按钮?
I want to remove a Button in his own onClick method after it's clicked. I tried it with the normal way:
layout.removeView(save);
But the button will not be removed and I get no error. If I want to add the Button I get an error because the button already excists.
I think it isn't working because I trie to remove the button during his OnClickHandler is active. So my Question is how can I remove the button after he is clicked?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试使用
button.setVisibility(Visibility.GONE) 设置其状态
Try to set its state with
button.setVisibility(Visibility.GONE)
隐藏起来怎么样?例如,在按钮 onclick 处理程序中,您可以执行以下操作:
How about just hide it? e.g. in your button onclick handler you can do something like:
这是完整的、经过充分测试的解决方案:
您还可以像这样从布局中完全删除视图(也经过测试):
Here's the complete, fully tested solution:
You can also completely remove the view from the layout like this (also tested):