Android复选框可见性问题

Android复选框可见性问题,第1张

概述我在我的代码中使用了一个复选框,当它检查时它会使textview和editText可见,但如果我取消选中de复选框,它们将继续显示而不是消失. 这是代码: final CheckBox save = (CheckBox) findViewById(R.id.checkbox); save.setOnClickListener(new OnClickListener() { 我在我的代码中使用了一个复选框,当它检查时它会使textvIEw和editText可见,但如果我取消选中de复选框,它们将继续显示而不是消失.

这是代码:

final CheckBox save = (CheckBox) findVIEwByID(R.ID.checkBox);        save.setonClickListener(new OnClickListener() {            public voID onClick(VIEw v) {                // Perform action on clicks,depending on whether it's Now checked                if (((CheckBox) v).isChecked()) {                    nameText.setVisibility(1);                    editname.setVisibility(1);                } else {                    nameText.setVisibility(0);                    editname.setVisibility(0);                }            }        });

并且在相对布局内部的xml的一部分:

<linearLayout androID:ID="@+ID/linearLayout3"            androID:orIEntation="horizontal"            androID:layout_wIDth="fill_parent"            androID:layout_height="wrap_content"            androID:layout_below = "@+ID/linearLayout2">    <TextVIEw androID:ID="@+ID/text"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"         androID:text="@string/name"         androID:visibility="invisible"/>    <EditText androID:ID="@+ID/name"         androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"         androID:layout_weight="1"        androID:visibility="invisible"/>        <CheckBox androID:ID="@+ID/checkBox"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:text="@string/save" /></linearLayout>

当我取消选中复选框时,我该怎么做才能使textVIEw和EditText消失?

谢谢!

解决方法 使用VIEw.VISIBLE,VIEw.INVISIBLE,VIEw.GONE来控制可见性(而不是0和1). 总结

以上是内存溢出为你收集整理的Android复选框可见性问题全部内容,希望文章能够帮你解决Android复选框可见性问题所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1137807.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存