我想在我的Android活动之一中动态创建一些复选框,但它不会呈现文本。Android复选框文本不显示
这里是我的简化代码...
布局XML:
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="10dip"> ... <LinearLayout android:id="@+id/register_attracted_to" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" /> ... </LinearLayout>
活动代码:
final LinearLayout attractedTo = (LinearLayout) findViewById(R.id.register_attracted_to); final CheckBox male = new CheckBox(this); male.setText("Male"); attractedTo.addView(male); final CheckBox female = new CheckBox(this); female.setText("Female"); attractedTo.addView(female);
我的 “真实” 的代码是比这更复杂(任何动态),这是为什么我没有简单地在布局中包含复选框。然而,即使是瘫痪我的代码仍然不能正确显示复选框文本。
这里有一个截图来证明(见“吸引到”一节),有一点点额外的证明,我的垂直布局表现为正常工作,不然:
我不会动态地添加用户界面组件,因为在开发时很难查看它们。开发人员需要运行整个应用程序才能看到添加的组件。我虚心建议增加他们的能见度消失了。它非常轻便,因为它们从来没有绘制过,但仍然可以找到(findViewById)。 –
复选框通过HttpRequest生成,这意味着您的建议是不可能的。 –