我想做一个考勤加任务系统。为此,我使用了复选框和线性布局。线性布局用于动态添加编辑文本框。当一个复选框被选中时,一个新的文本字段是可见的,当它被取消选中时,文本字段必须被隐藏。我已经使用的代码部分的东西像这样:现在如何在android中隐藏动态创建的EditText框?
public void onCheckBoxClicked(View v) {
boolean checked = ((CheckBox) v).isChecked();
EditText tv;
tv = new EditText(this);
tv.setLayoutParams(new RadioGroup.LayoutParams(RadioGroup.LayoutParams.WRAP_CONTENT,
RadioGroup.LayoutParams.WRAP_CONTENT));
tv.setText(one.getText().toString()+ "'s task today?");
tv.setBackgroundColor(0xff66ff66); // hex color 0xAARRGGBB
tv.setPadding(20, 20, 20, 20);// in pixels (left, top, right, bottom)
switch (v.getId()) {
case R.id.checkBox1:
if(checked) {
list.addView(tv);
Toast.makeText(getApplicationContext(), one.getText().toString() + " is present", Toast.LENGTH_SHORT).show();
}
if(!checked) {
tv.setVisibility(EditText.GONE); //problem exists here--is not executing
Toast.makeText(getApplicationContext(), one.getText().toString() + " is absent", Toast.LENGTH_SHORT).show();
}
break;
,我可以很容易地得到一个编辑的文本字段当我检查盒子,但在取消选中它,编辑文本字段不躲。我该如何解决它?
尝试View.GONE .. – rafid059 2015-02-23 10:01:02
我试过了。视图也不起作用。 – 2015-02-23 10:04:30
尝试使用'checkBox1.isChecked()'而不是'checked' – 2015-02-23 10:10:44