Reputation: 5400
For some reason using setInputType
for EditText
forces it into a single line. I need the EditText to accept NumberSigned.
I tried using InputFilter
such that it returns "" if source.charAt(i)
is not 0-9 or dot or + or -
But how to allow newline character? I need to be able to enter in multiple lines in the EditText.
I tried both in xml and code:
et = new EditText(this);
et.setText(getResources().getString(R.string.default_value));
et.setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED);
et.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT));
linearLayout.addView(et);
the setText enters a string:
<string name="default_value">1,2,3\n4,5,6\n7,8,9</string>
which is shown as 1 2 3 4 5 6 7 8 9.
I tried using setLines()
and setMaxLines()
but no luck.
I think the reason it is forced into a single line is because newline character is not a part of InputType NumberSigned.
Upvotes: 1
Views: 223
Reputation: 762
If you want input as signed integer, then you can use
...
android:digits="0123456789 \n"
...
PS : Don't forget the SPACE between 9
and \n
Upvotes: 1