Reputation: 45
This might already be described somewhere. However, I do not really know what to search for.
The feature I'm looking for is when you have a form where you can add more details. For example, there could be a field for adding your email address. However, if you want to add another email address you could click on a button and it will display another input field.
Ie
Name [ ]
Email [ ]
[ADD]
Then after clicking add you would have
Name [ ]
Email [ ]
Email [ ]
[ADD]
Thanks
Upvotes: 1
Views: 62
Reputation: 16729
Following code will help you to add edittext when button is clicked...
LinearLayout linearH = new LinearLayout(context);
LinearLayout.LayoutParams edtTextParams=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT,1.0f);
EditText edtText =new EditText(context);
linearH.addView(edtText , edtTextParams);
Upvotes: 1
Reputation: 667
this simple example is how you can add an edittext when the button is clicked in your code:
LinearLayout ll = (LinearLayout)findViewById(R.id.mainLayout);
EditText et = new EditText(this);
ll.addView(et);
Upvotes: 1