我正在开发联系人应用程序,它添加电子邮件地址、电话号码。我必须在代码本身中动态创建编辑文本。我不知道如何以及在哪里实现这个逻辑,建议任何帮助将不胜感激。
最佳答案
你可以这样创建它:
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
方法以及介于两者之间的所有内容。
有一个更通用的例子in this question ,以及这些过程的简要说明 in this blog .
关于android - 在 Android 中以编程方式生成编辑文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12985825/