在机器人编程方式生成编辑文本 [英] Generating Edit Text Programatically in android
问题描述
我开发联系应用,这增加了电子邮件地址,电话号码。我要在$ C C本身$动态创建编辑文本。我不知道如何以及在哪里实施这个逻辑,提出任何帮助,将不胜感激。
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.
还有一个更通用的例子<一href="http://stackoverflow.com/questions/4801631/how-to-create-gui-in-android-instead-of-using-xml">in这个问题,并在此博客这些过程良好的破败。
There is a more generic example in this question, and a good rundown of these processes in this blog.
这篇关于在机器人编程方式生成编辑文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!