[英]How to hide and unhide box from checkbox
I'm a student of android developer. 我是android开发人员的学生。 I need to make a project and I've ran into a problem.
我需要做一个项目,但遇到了问题。 basically the problem is that i need to make the box of a checkBox disappear and only after pushing a specific button, the box will appear and be clickable.
基本上,问题是我需要使一个复选框的框消失,并且仅在按下特定按钮后,该框才会出现并且可以单击。 from my searches i've found that when i write:
从我的搜索中,我发现当我写的时候:
myCheckBox.setButtonDrawable(new ColorDrawable(Color.TRANSPARENT));
it will disappear and it's good but couldn't find the way to make it appear after that.. thanks a lot. 它会消失,很好,但是在那之后找不到使它出现的方法..非常感谢。 :)
:)
You can achieve that my making the view disappear either by using 您可以使用以下方法实现使视图消失
myCheckBox.setVisibility(View.GONE);
(OR)
myCheckBox.setVisibility(View.INVISIBLE);
And again you can make it to appear by 再一次,你可以让它出现
myCheckBox.setVisibility(View.VISIBLE);
Hope this is helpful:) 希望这会有所帮助:)
You need to use 您需要使用
yourCheckBox.setVisibility(View.GONE);
to make that visible again, 使它再次可见,
yourCheckBox.setVisibility(View.VISIBLE);
You can get the currently assigned drawable with getButtonDrawable()
and store it in a field, for example: 您可以使用
getButtonDrawable()
获取当前分配的drawable并将其存储在字段中,例如:
class Foo {
private Drawable oldDrawable;
private CheckBox myCheckBox;
public void hideCheckbox() {
oldDrawable = myCheckBox.getButtonDrawable();
myCheckBox.setButtonDrawable(new ColorDrawable(Color.TRANSPARENT));
}
public void showCheckbox() {
myCheckBox.setButtonDrawable(oldDrawable);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.