活动中的Android Studio名称标签 [英] Android studio name tabs in activity

查看:97
本文介绍了活动中的Android Studio名称标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个editText,用户可以在其中选择2到8之间的数字.例如,如果用户选择5,那么我想在同一活动中显示5个新的editText.我怎样才能做到这一点?我发现片段可以通过某种方式实现,但是直到现在我都没有找到非常有用的教程.

I have an editText in which an user can choose a number between 2 and 8. For example, if user selected 5 then I want to show 5 new editTexts in the same activity. How can I do this? I found that is somehow possible with fragments, but I didn't find a very useful tutorial until now.

推荐答案

如@kumud kala所述在Scrollview中添加一个线性布局,然后您可以像这样以编程方式创建一个EditText.

As said by @kumud kala Add a Linear Layout inside a Scrollview and then you can create a EditText programmatically like this.

LineLinearLayout llayout = findViewById(R.id.yourlinearlayout);
EditText yourEditText= new EditText(this);
yourEditText.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
llayout.addView(yourEditText);

如果您需要更多editText,可以初始化一个EditText数组,然后循环遍历编辑文本的数量

If you want more editTexts, you can initialize an EditText Array, and then loop through the number of edittexts

这篇关于活动中的Android Studio名称标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆