How to limit EditText lines to 1 by coding (ignoring enter)?
Posted
by
Vahe Musinyan
on Stack Overflow
See other posts from Stack Overflow
or by Vahe Musinyan
Published on 2012-06-22T07:59:52Z
Indexed on
2012/06/22
9:16 UTC
Read the original article
Hit count: 112
android
|android-edittext
I am trying to ignore the enter key, but i do not want to use onKeyDown() function.
There is a way to do this in xml: 1. android:maxLines = "1" 2. android:lines = "1" 3. android:singleLine = "true"
I actually want to do the last one by coding. Does anyone know how to do that?
for (int i=0; i<numClass; i++) {
temp_ll = new LinearLayout(this);
temp_ll.setOrientation(LinearLayout.HORIZONTAL);
temp1 = new EditText(this);
InputFilter[] FilterArray = new InputFilter[1];
FilterArray[0] = new InputFilter.LengthFilter(12);
temp1.setFilters(FilterArray); // set edit text length to max 12
temp1.setHint(" class name ");
temp1.setSingleLine(true);
temp_ll.addView(temp1);
frame.addView(temp_ll);
}
ll.addView(frame);
© Stack Overflow or respective owner