Text cannot be written in multiple lines in EditText - android

EditText has strange behavior. Whatever I write in it is written in only single line. I am not able write text in a second line (new line).
Why I cannot write text in multiple lines?
Here's my EditText
<EditText
android:id="#+id/tbr_des"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="#string/des"
android:inputType="textCapSentences"
android:textColorHint="#color/text_hint"
android:textColor="#color/text"
android:maxLength="300"
android:layout_margin="10dp"
android:padding="5dp"
android:gravity="start"
android:background="#drawable/edit_text"/>
Whereas my another activity has same EditText with all same attributes, and it lets me write in multiple lines. I'm using LinearLayout in both xml.
EditText of another layout.
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="#string/des"
android:textColorHint="#color/text_hint"
android:textColor="#color/text"
android:maxLength="300"
android:layout_margin="10dp"
android:padding="5dp"
android:gravity="start"
android:background="#drawable/edit_text"/>
I also tried android:singleLine="false" but doesn't work.

Use textCapSentences|textMultiLine as its inputType
<EditText
...
android:inputType="textCapSentences|textMultiLine"
... />

By default all the EditText widgets in Android are multi-lined.
Here is some sample code:
<EditText
android:inputType="textMultiLine" <!-- Multiline input -->
android:lines="8" <!-- Total Lines prior display -->
android:minLines="6" <!-- Minimum lines -->
android:gravity="top|left" <!-- Cursor Position -->
android:maxLines="10" <!-- Maximum Lines -->
android:layout_height="wrap_content" <!-- Height determined by content -->
android:layout_width="fill_parent" <!-- Fill entire width -->
android:scrollbars="vertical" <!-- Vertical Scroll Bar -->
/>

The problem occurs due to
android:inputType="textCapSentences"
if you remove this your code will work fine as you expected.

Related

NextFocusRight doesn't focus on the right, but down

I'm work on an app with multiple edittext.
When an edittext take the whole width, the nextfocusdown is working properly.
But when there is two edittext at the same height (each edittext takes half of the width), I want to give the focus from the left one to the right one.
But when i write nextFocusRight="id/EDIT_RIGHT" in my xml, the focus doesn't goes to the right edittext but goes to edittext under the left one.
<!-- EDIT LEFT-->
<EditText
android:id="#+id/EDIT_LEFT"
android:layout_width="165dp"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:hint="#string/edit_left_hint"
android:nextFocusRight="#id/EDIT_RIGHT"
tools:ignore="Autofill"/>
<!-- EDIT RIGHT-->
<EditText
android:id="#+id/EDIT_RIGHT"
android:layout_width="165dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:hint="#string/edit_right_hint"
android:nextFocusDown="#id/EDIT_DOWN"
tools:ignore="Autofill"/>
You have to use like this -
<!-- EDIT LEFT-->
<EditText
android:id="#+id/EDIT_LEFT"
android:layout_width="165dp"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:hint="#string/edit_left_hint"
android:imeOptions="actionNext"
android:nextFocusRight="#+id/EDIT_RIGHT"
tools:ignore="Autofill"/>
<!-- EDIT RIGHT-->
<EditText
android:id="#+id/EDIT_RIGHT"
android:layout_width="165dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:hint="#string/edit_rgiht_hint"
android:imeOptions="actionNext"
android:nextFocusDown="#id/EDIT_DOWN"
tools:ignore="Autofill"/>
You should use android:nextFocusRight="#+id/EDIT_RIGHT" instead of android:nextFocusRight="#id/EDIT_RIGHT" because you are using this edittext before creating it and use imeOptions.

I am unable to add more than one line edittext android?

This is my XML property code. I am trying to add a multiline edittext in android, but unable to do so.
android:ems="10"
android:hint="Kindly enter the Delivery Address."
android:id="#+id/et_text"
android:layout_width="351dp"
android:``layout_height="153dp"
android:textDirection="firstStrong"
android:gravity="top|left"
android:lines="6"
android:inputType="textPostalAddress"
By default EditText in android are multi-lined.
Try this sample code.
<EditText
android:inputType="textMultiLine"
android:lines="8"
android:minLines="6"
android:gravity="top|left"
android:maxLines="10"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:scrollbars="vertical"
/>
Add this line in your edittext
android:inputType="textMultiLine|textPostalAddress"
Try This
<EditText
android:inputType="textMultiLine" <!-- Multiline input -->
android:lines="8" <!-- Total Lines prior display -->
android:minLines="6" <!-- Minimum lines -->
android:gravity="top|left" <!-- Cursor Position -->
android:maxLines="10" <!-- Maximum Lines -->
android:layout_height="wrap_content" <!-- Height determined by content -->
android:layout_width="fill_parent" <!-- Fill entire width -->
android:scrollbars="vertical" <!-- Vertical Scroll Bar -->
/>

EditText won't write into single line

I'm making a calculator and user input is contained in EditText. Input is typed through buttons on screen, so Android keyboard is disabled. However, I want it to write all input in one line and when line reaches border, it needs to be ellipsized and then horizontally scrollable so you can reach whole text.
I tried doing this by setting android:maxLines="1" and android:ellipsize="end", but that doesn't work. Text is still in multiple lines, but only one line is visible and you need to scroll vertically to see other lines. I also tried using android:singleLine="true", but that makes EditText completely unusable.
This is EditText XML:
<EditText
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#color/colorBlue"
android:textAlignment="textEnd"
android:textSize="40sp" />
I think this will work for you. Let me know if it works.
<EditText
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#color/colorBlue"
android:textAlignment="textEnd"
android:textSize="40sp"
android:inputType="text"
android:maxLines="1"
android:lines="1"
android:scrollHorizontally="true"
android:ellipsize="end"/>
This post might help you as well.
For single line in EditText, you just need to set two properties:
android:inputType="text"
android:maxLines="1"
Adding this line in the edittext make scrollable singleline text.
android:inputType="textShortMessage"
**This example helps you to create multiline EditText in Android.**
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
tools:context=".MainActivity"
>
<!--
android:scrollbars="vertical"
It will display a vertical scrollbar if the EditText text exceed
3 lines (android:maxLines).
-->
<EditText
android:id="#+id/et"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginBottom="10dp"
android:hint="Multiline EditText by XML layout"
android:fontFamily="sans-serif-condensed"
android:background="#d3d7b6"
android:minLines="2"
android:maxLines="3"
android:scrollbars="vertical"
android:inputType="textMultiLine"
/>
<EditText
android:id="#+id/et2"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:padding="10dp"
android:fontFamily="sans-serif-condensed"
android:hint="Multiline EditText programmatically"
android:background="#d4d7a5"
android:layout_below="#+id/et"
/>
</RelativeLayout>

Android EditText not showing multilines

I am reading data from file buffer and storing it into a string. I am loading the same string by setext to editText component. However knowing multiple lines it is displaying entire file into only a single line. My xml file is as below:
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/btnlogclear"
android:layout_toRightOf="#+id/btnemaillog" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="224dp"
android:orientation="vertical" >
<EditText
android:id="#+id/editLog"
android:layout_width="wrap_content"
android:layout_height="177dp"
android:ems="10"
android:enabled="false"
android:gravity="left|top"
android:inputType="textMultiLine"
android:scrollbars="vertical"
android:scrollHorizontally="false" >
<requestFocus />
</EditText>
</LinearLayout>
</ScrollView>
It is still showing a single line.
Any clues to solve the issue.
Abhimoh
Use this in the xml:
android:inputType="textMultiLine" <!-- Multiline input -->
android:minLines="6" <!-- Optional min number of lines -->
android:maxLines="10" <!-- Optional max number of Lines -->
Use
android:layout_height="wrap_content"
for LinearLayout and
android:layout_height="wrap_content"
for EditText
Change the height of LinearLayout to wrap_content so that EditText will get enough space to expand.Now the EditText can only extend upto 224dp. I think that's the reason why EditText is not showing multiple lines.
I finally managed it by using textview and setMovementMethod(new ScrollingMovementMethod());
Thanks guys for help! Closing this post

Allow multi-line in EditText view in Android?

How to allow multi-line in Android's EditText view?
By default all the EditText widgets in Android are multi-lined.
Here is some sample code:
<EditText
android:inputType="textMultiLine" <!-- Multiline input -->
android:lines="8" <!-- Total Lines prior display -->
android:minLines="6" <!-- Minimum lines -->
android:gravity="top|start" <!-- Cursor Position -->
android:maxLines="10" <!-- Maximum Lines -->
android:layout_height="wrap_content" <!-- Height determined by content -->
android:layout_width="match_parent" <!-- Fill entire width -->
android:scrollbars="vertical" <!-- Vertical Scroll Bar -->
/>
You may find it better to use:
<EditText
...
android:inputType="textMultiLine"
/>
This is because android:singleLine is deprecated.
This works for me, actually these 2 attributes are important: inputType and lines. Besides, you may need a scrollbar, the code below shows how to make one:
<EditText
android:id="#+id/addr_edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top|left"
android:inputType="textEmailAddress|textMultiLine"
android:lines="20"
android:minLines="5"
android:scrollHorizontally="false"
android:scrollbars="vertical" />
This is how I applied the code snippet below and it's working fine. Hope, this would help somebody.
<EditText
android:id="#+id/EditText02"
android:gravity="top|left"
android:inputType="textMultiLine"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:lines="5"
android:scrollHorizontally="false"
/>
Cheers! ...Thanks.
EditText has singleLine property. You can set in the XML or by calling setSingleLine(false);
http://developer.android.com/reference/android/widget/TextView.html#setSingleLine%28%29
Try this,
add these lines to your edit text view, i'll add mine. make sure you understand it
android:overScrollMode="always"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
<EditText
android:inputType="textMultiLine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText_newprom_description"
android:padding="10dp"
android:lines="5"
android:overScrollMode="always"
android:scrollbarStyle="insideInset"
android:minLines="5"
android:gravity="top|left"
android:scrollbars="vertical"
android:layout_marginBottom="20dp"/>
and on your java class make on click listner to this edit text as follows, i'll add mine, chane names according to yours.
EditText description;
description = (EditText)findViewById(R.id.editText_newprom_description);
description.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
view.getParent().requestDisallowInterceptTouchEvent(true);
switch (motionEvent.getAction() & MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_UP:
view.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
return false;
}
});
this works fine for me
android:inputType="textMultiLine"
This code line work for me. Add this code you edittext in your xml file.
Just add this
android:inputType="textMultiLine"
in XML file on relevant field.
if some one is using AppCompatEditText then you need to set inputType="textMultiLine" here is the code you can copy
<androidx.appcompat.widget.AppCompatEditText
android:padding="#dimen/_8sdp"
android:id="#+id/etNote"
android:minLines="6"
android:singleLine="false"
android:lines="8"
android:scrollbars="vertical"
android:background="#drawable/rounded_border"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_25sdp"
android:layout_marginTop="32dp"
android:layout_marginEnd="#dimen/_25sdp"
android:autofillHints=""
android:gravity="start|top"
android:inputType="textMultiLine"
/>
for background
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="#dimen/_5sdp"/>
<stroke android:width="1dp" android:color="#C8C8C8"/>
</shape>
All of these are nice but will not work in case you have your edittext inside upper level scroll view :) Perhaps most common example is "Settings" view that has so many items that the they go beyond of visible area. In this case you put them all into scroll view to make settings scrollable. In case that you need multiline scrollable edit text in your settings, its scroll will not work.
To disable number of lines that was previously assigned in theme use xml attribute: android:lines="#null"
<EditText
android:id="#id/editText" //id of editText
android:gravity="start" // Where to start Typing
android:inputType="textMultiLine" // multiline
android:imeOptions="actionDone" // Keyboard done button
android:minLines="5" // Min Line of editText
android:hint="#string/Enter Data" // Hint in editText
android:layout_width="match_parent" //width editText
android:layout_height="wrap_content" //height editText
/>
I learned this from http://www.pcsalt.com/android/edittext-with-single-line-line-wrapping-and-done-action-in-android/, though I don't like the website myself. If you want multiline BUT want to retain the enter button as a post button, set the listview's "horizontally scrolling" to false.
android:scrollHorizontally="false"
If it doesn't work in xml, doing it programmatically weirdly works.
listView.setHorizontallyScrolling(false);
Another neat thing to do is to use android:minHeight along with android:layout_height="wrap_content". This way you can set the size of the edit when it's empty, and when the user inputs stuff, it stretches according to how much the user inputs, including multiple lines.
<EditText
android:hint="Address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textMultiLine|textNoSuggestions"
android:id="#+id/edittxtAddress"
android:layout_marginLeft="#dimen/textsize2"
android:textColor="#android:color/white"
android:scrollbars="vertical"
android:minLines="2"
android:textStyle="normal" />
and in Activity to remove "\n" is user press nextline
String editStr= edittxtAddress.getText().toString().trim();
MyString= editStr.replaceAll("\n"," ");

Categories

Resources