Android-从代码构建动态表单

Android-从代码构建动态表单,第1张

Android-从代码构建动态表单

这些小部件可以像其他所有小部件一样进行创建:

final Context context; final LinearLayout layout = (LinearLayout)findViewById(R.id.your_layout);final RadioGroup group = new RadioGroup(context);final RadioButton button1 = new RadioButton(context);button1.setId(button1_id); // this id can be generated as you like.group.addView(button1,    new RadioGroup.LayoutParams(        RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT));final RadioButton button2 = new RadioButton(context);button1.setId(button2_id); // this id can be generated as you like.button2.setChecked(true);group.addView(button2,    new RadioGroup.LayoutParams(        RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT));layout.addView(group,    new LinearLayout.LayoutParams(        LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));

我尚未测试此代码,因此可能包含一些错误。但我希望你能明白。



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5475830.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存