一个EditText属性的设置在Android的动态添加 [英] Setting attributes of an EditText added dynamically in Android

查看:520
本文介绍了一个EditText属性的设置在Android的动态添加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的深化发展Android应用程序,这将下载一个xml并与多家edittexts,复选框,纺纱的显示布局等动态添加这样的:

I am developping an android app which downloads an xml and displays a layout with a number of edittexts, checkboxes, spinners, etc. added dynamically like this:

LinearLayout ll = new LinearLayout(this);
EditText nameField = new EditText(this);
ll.addView(nameField);
ScrollView sv = new ScrollView(this);
sv.addView(ll);
setContentView(sv);

我在与设置一些属性,以一个EditText麻烦加入这种方式。对于Android的〔实施例:maxlength属性可以很容易地在XML的布局设置,但我发现没有办法做同样在Java code

I'm having trouble with setting some properties to an EditText added this way. For examle android:maxLength attribute can easily be set in an xml layout but I found no method to do the same in the java code.

该怎么办呢?

谢谢,
佐尔坦来自匈牙利

Thanks, Zoltán from Hungary

推荐答案

如果你看一下XML属性的文档,它列出了你可以在你的java的 code为每个属性

If you look at the XML attributes in the docs, it lists the corresponding method you can call in your java code for each attribute

因此​​,例如设置最大长度属性可以通过 setFilters(输入过滤器)的方法来实现。

So for example setting the maxLength attribute can be accomplished through the setFilters(InputFilter) method.

这篇关于一个EditText属性的设置在Android的动态添加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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