Man8Blue
Man8Blue

Reputation: 1197

How to add EditText elements in Android on the same activity?

I have a DetailsActivity which has a TextView and TimeEditText for Date. User can add a date in that. There is a Button called Add Detail

I want that when a user enters a date like d-m-yy (future) then below this TimeEditText element, the activity should show a no. of WeekEditText as

Week1: WeekEditText1 (To add details for 1st week)

Week2: WeekEditText2 (To add details for 2nd week) and so on.

The total no. of week is (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.

But is it possible to show EditText on same page below TimeEditText after user enters a date?

Upvotes: 0

Views: 479

Answers (2)

codeMagic
codeMagic

Reputation: 44571

Have a Button that when clicked adds the number of EditTexts you need

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. Something like that ought to work for you

Upvotes: 1

Vishal Disawar
Vishal Disawar

Reputation: 144

You can dynamically inflate a layout or layout element such as and Edit Text. For Example,

if(TimeEditText.getText != null)
 EditText et = new EditText();

Upvotes: 0

Related Questions