当我点击一个按钮时,我想添加一个编辑文本字段到我的应用程序,但我不更改布局。只需将它添加到由xml文件定义的现有一个之下。 可以说我有一个联系人应用程序,如果用户需要添加额外的字段点击按钮并创建一个! 如何做到这一点?动态添加编辑文本
Q
动态添加编辑文本
-2
A
回答
1
你可以做的是在面板中使用EditText,即将它们分组在面板中,然后有一个按钮,然后在按钮上单击创建一个EditText的实例并将其添加到相关面板。这样你就不会限制自己只能添加一个面板,而是和用户想添加的一样多。
5
在布局中保留一个EditText项并将其可见性设置为不见了。
<EditText android:visibility="gone" android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
然后单击按钮设置可见的onclick事件可见。
或
您可以以编程方式添加EditText项目。
将LinearLayout添加到您的xml中。
<LinearLayout
android:id="@+id/editTextGroupLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
在按钮上单击事件以编程方式添加EditText。
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.editTextGroupLayout);
EditText editTextView = new EditText(this);
editTextView.setGravity(Gravity.CENTER);
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT, 1);
editTextView.setLayoutParams(params);
linearLayout.addView(editTextView);
希望这会有所帮助。
0
首先你要从web服务中调用数据。例如: description = Parser.getDescription;
在XML布局:
<Button android:id="@+id/button" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:onClick="@string/ButtonClick"/>
<EditText android:id="@+id/note" android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
代码:
ButtonName = (Button)findViewById(R.id.note);
Data = (EditText)findViewById(R.id.note);
public void ButtonClick(View v){
description = Parser.getDescription;
Data.settext(description);
}
相关问题
- 1. 编辑动态文本HTML
- 2. 将动态图像添加到编辑文本中
- 3. Android:动态添加线性布局中的编辑文本框?
- 4. 动态添加TinyMCE编辑器到文本框
- 5. 动态编辑文本和文本框
- 6. 从线性布局动态添加编辑文本中获取文本
- 7. 动态添加文本框
- 8. 动态TextWatcher ontextchange为编辑文本
- 9. 如何动态编辑“noRowsToShow”文本?
- 10. Access 2010子文本编辑和添加
- 11. 添加按钮,动态也添加文本框,动态AngularJS
- 12. 动态添加文本框以动态添加面板
- 13. 从动态编辑文本框中清除文本?
- 14. QT创建按钮,将文本添加到文本编辑框
- 15. 移动编辑文本
- 16. C#动态添加文本到tabcontrol
- 17. 添加和删除动态文本框
- 18. 在图像上添加动态文本
- 19. 使用jquery动态添加文本框
- 20. 验证动态添加文本框
- 21. Javascript动态添加文本框值
- 22. 动态添加本地化文件C#
- 23. 在flex中动态添加文本
- 24. 在android中动态添加文本框
- 25. gwt动态添加文本框
- 26. Javascript删除文本框动态添加
- 27. JavaFX动态添加新文本字段
- 28. Datepicker问题,动态添加文本框
- 29. 在asp.net中动态添加文本框
- 30. 动态添加文本框,并在MySQL
是它TextField的有限数量的可打开?如果是这样的话,你可以通过触发buttonClick事件来看到这些转向。 – AndroidHustle 2011-12-15 11:07:25