问题
How can I create a new checkbox every time I click a button and how do I hide a check box?
Also, why doesn't checkbox.setVisibility(View.Gone); work the same way textview.setVisibility(View.Gone) worked?
回答1:
LinearLayout my_layout = (LinearLayout)findViewById(R.id.my_layout);
button.setOnClickListener(new onClickListener(){
void onClick(){
CheckBox checkBox = new CheckBox(this);
checkBox.setText(Str_Array[i]);
my_layout.addView(checkBox);
}
});
回答2:
Create the checkbox in the layout and set visibility to View.GONE, and when you need set visibility to View.VISIBLE to show the checkbox
More info here
来源:https://stackoverflow.com/questions/26454531/how-to-make-a-new-checkbox-appear-on-clicking-button-in-android