Friday, 6 September 2013

EditText attributes programmatically - text won't wrap

EditText attributes programmatically - text won't wrap

I have the following EditText working as expected.
<EditText
android:id="@+id/etMensagem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_message"
android:minLines="4"
android:text="@string/send"
android:inputType="textCapSentences|textMultiLine"/>
But the attributes hint, minLines, text and inputType need to be set
programmatically.
Here is my try:
edit_text.setText(context.getString(R.string.enviar_mensagem));
edit_text.setMinLines(4);
edit_text.setHint(context.getString(R.string.hint_message));
edit_text.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES |
InputType.TYPE_TEXT_FLAG_MULTI_LINE);
But when I do this, the text does not wrap. Even though it's a multiline
EditText, it keeps text on a single line, unlike the XML version.
What am I missing?

No comments:

Post a Comment