当我点击一个按钮时,我想添加一个编辑文本字段到我的应用程序,但我不更改布局。只需将它添加到由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. 单击动态添加编辑文本
- 2. 编辑动态文本HTML
- 3. 富文本编辑器...动态添加类
- 4. 如何在android中动态添加和使用编辑文本?
- 5. 动态添加TinyMCE编辑器到文本框
- 6. HTML动态添加图像到iframe(如文本编辑器)
- 7. 将编辑文本动态添加到布局
- 8. 在对话框中添加动态编辑文本
- 9. 将动态图像添加到编辑文本中
- 10. Android:动态添加线性布局中的编辑文本框?
- 11. 动态编辑文本和文本框
- 12. 从线性布局动态添加编辑文本中获取文本
- 13. 动态添加一个tinymce编辑器
- 14. 动态添加编辑控件和静态文本到对话框visual C++
- 15. 添加编辑或删除编辑器Google动态分页
- 16. 动态添加文本框
- 17. 添加TinyMCE的编辑器脚本jquery的动态
- 18. 动态简单文本编辑器Java
- 19. 动态编辑表td文本
- 20. 动态TextWatcher ontextchange为编辑文本
- 21. 如何动态编辑“noRowsToShow”文本?
- 22. Access 2010子文本编辑和添加
- 23. 添加2个textChangedListeners来编辑文本?
- 24. 动态添加文本框以动态添加面板
- 25. 添加按钮,动态也添加文本框,动态AngularJS
- 26. 如何在单击按钮时动态添加编辑文本框?
- 27. 有没有什么办法根据web服务动态添加编辑文本?
- 28. 我想编辑Eclipse中的自动文本添加功能
- 29. PyQt4 - 添加文本编辑区域动画示例
- 30. 添加/编辑
是它TextField的有限数量的可打开?如果是这样的话,你可以通过触发buttonClick事件来看到这些转向。 – AndroidHustle 2011-12-15 11:07:25