How to make a new checkbox appear on clicking button in Android

こ雲淡風輕ζ 提交于 2019-12-12 01:29:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!