Generating Edit Text Programmatically in Android(在 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.
在这个问题中有一个更通用的例子,以及这些流程的详细介绍在此博客中一个>.
There is a more generic example in this question, and a good rundown of these processes in this blog.
这篇关于在 Android 中以编程方式生成编辑文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Android 中以编程方式生成编辑文本
基础教程推荐
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
