[英]How to add EditText elements in Android on the same activity?
I have a DetailsActivity
which has a TextView
and TimeEditText
for Date . 我有一个DetailsActivity
具有Date的TextView
和TimeEditText
。 User can add a date in that. 用户可以在其中添加日期。 There is a Button
called Add Detail
有一个名为“ Add Detail
的Button
I want that when a user enters a date like dm-yy (future) then below this TimeEditText
element, the activity should show a no. 我希望当用户输入类似dm-yy(将来的日期)的日期,然后在此TimeEditText
元素下方时,活动应显示否。 of WeekEditText
as 的WeekEditText
为
Week1: WeekEditText1
(To add details for 1st week) WeekEditText1
: WeekEditText1
(添加第一周的详细信息)
Week2: WeekEditText2
(To add details for 2nd week) and so on. Week2: WeekEditText2
(添加第二周的详细信息) ,依此类推。
The total no. 总数 of week is (AddedDate - CurrentDate)/7
的星期是(AddedDate - CurrentDate)/7
One of way of doing is calling another new activity on clicking Add Detail
button and then showing all EditTexts on next activity while passsing AddedDate
etc through Intent. 一种方法是在单击“ Add Detail
按钮时调用另一个新活动,然后在下一个活动中显示所有EditText ,同时通过Intent传递AddedDate
等。
But is it possible to show EditText
on same page below TimeEditText
after user enters a date? 但是,在用户输入日期之后,是否可以在TimeEditText
同一页面上显示EditText
?
Have a Button
that when clicked adds the number of EditText
s you need 有一个Button
,单击该Button
可添加所需的EditText
数
public void onClick(View v)
{
// do whatever else you need here
int numWeeks =(AddedDate - CurrentDate)/7;
for (i=1; i<=numWeeks;i++)
{
EditText et = new EditText(YourActivity.this);
// add whatever here
}
}
You can add whatever kind of Layout
you want before creating the EditText
then add each one to that Layout
. 您可以在创建EditText
之前添加所需的任何Layout
,然后将每个Layout
添加到该Layout
。 Something like that ought to work for you 这样的事情应该为您工作
You can dynamically inflate a layout or layout element such as and Edit Text. 您可以动态地增加布局或布局元素,例如和编辑文本。 For Example, 例如,
if(TimeEditText.getText != null)
EditText et = new EditText();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.