Android CheckBox text not displaying

后端 未结 4 1421
悲哀的现实
悲哀的现实 2021-01-11 20:50

I\'m trying to dynamically create some CheckBoxes in one of my Android activities, but it\'s not rendering the text.

Here is my simplified code...

  1. L

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-11 21:51

    you are not setting the Layout parameters, Layout parameter says how the control will be shown

    final CheckBox female = new CheckBox(this);
    female.setText("Female");
    female .setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f));
    attractedTo.addView(female);
    

提交回复
热议问题