在Android中以编程方式生成编辑文本 [英] Generating Edit Text Programmatically in Android

查看:76
本文介绍了在Android中以编程方式生成编辑文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发联系人应用程序,该应用程序将添加电子邮件地址,电话号码.我必须在代码本身中动态创建编辑文本.我不知道如何以及在何处实施此逻辑,建议提供任何帮助将不胜感激.

I'm developing Contact Application, which adds Email address, phone number. I have to create edit text dynamically in code itself. I don't know how and where to implement this logic, suggest any help would be grateful.

推荐答案

您可以这样创建它:

EditText myEditText = new EditText(context); // Pass it an Activity or Context
myEditText.setLayoutParams(new LayoutParams(..., ...)); // Pass two args; must be LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, or an integer pixel value.
myLayout.addView(myEditText);

这可以在UI线程的任何地方实现;点击侦听器,onCreate方法以及介于两者之间的所有内容.

This can be implemented anywhere on the UI thread; a click listener, an onCreate method, and everything in between.

在此问题中有一个更通用的示例 ,并在此博客中 a>.

There is a more generic example in this question, and a good rundown of these processes in this blog.

这篇关于在Android中以编程方式生成编辑文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆