Reputation: 17083
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 need to be set programmatically (all but layout_width and height).
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?
Upvotes: 1
Views: 2631
Reputation: 17083
Found the answer here: https://stackoverflow.com/a/5800511/770467
For setting the input type for an EditText programatically you have to specify that input class type is text
Final solution:
etMensagem.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
Upvotes: 7
Reputation: 6350
I think u have to do this
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="none"
android:singleLine="false"
Upvotes: 1