[英]New EditText when button pressed
I have a button within a relative layout, and want it to create a new EditText in a different relative layout when pressed (a completely new EditText, not just turning the visibility on/off). 我在相对布局中有一个按钮,希望它在按下时可以在不同的相对布局中创建一个新的EditText(一个全新的EditText,而不仅仅是打开/关闭可见性)。 This answer has helped, however I cannot change it to make it add an EditText instead of adding a new TextView.
这个答案有所帮助,但是我无法更改它以使其添加EditText而不是添加新的TextView。 I don't need it to save the text inside any views or anything, just create another EditText, similar to an add contact button.
我不需要它来将文本保存在任何视图或任何内容内,只需创建另一个EditText,类似于添加联系人按钮即可。
private EditText createNewEditText() {
final LayoutParams lparams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
final EditText edittext = new EditText(this);
Editext.setLayoutParams(lparams);
return edittext;
}
just make new relative in xml file 只是在xml文件中创建新的亲戚
add this edittext like this 像这样添加此edittext
rl.addView(createNewEditText());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.