Question

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);

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.

How can I do it when hawing to add dynamically?

Thanks, Zoltán from Hungary

Was it helpful?

Solution

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top