简体   繁体   English

按下按钮时新建EditText

[英]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.

相关问题 按下按钮时清除edittext - clear edittext when button is pressed 按下最近的应用程序按钮时清除EditText - Clearing an EditText when the recent apps button is pressed 如何创建EditText&Button,以便只要按下按钮存储prev值,EditText就应该接受新输入? - How to create EditText & Button so that EditText should take new input whenever button is pressed storing prev value? 按下按钮时清除编辑文本焦点并隐藏键盘 - Clear edittext focus and hide keyboard when button is pressed 在android中按下导航后退按钮时保留edittext数据 - preserve edittext data when navigation back button pressed in android 当 EditText 为空白并按下按钮时,Android 应用程序崩溃 - Android app crashes when EditText is blank and button pressed 按下后退按钮时未加载新首选项 - New Preferences not loading when back button is pressed 按Enter键或按钮时,如何将EditText中的文本打印到textview - How do I print text from EditText to a textview when pressed enter or a button 在按下返回按钮后再次创建活动时,EditText返回相同的值 - EditText returning same value when activity is created again after the back button is pressed 我的问题是,当按下按钮时,为什么我输入的编辑文本中的文本不会显示在另一个文本视图中? - My question is why won't my inputted text into an edittext show up in another textview when a button is pressed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM