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
Related
I am implementing a programming language code editor for the same I need EditText horizontally scrollable also multiline and I want to turn off the autocorrect and the autosuggest. Suppose, I want to write
int main(){
printf("This is an awesome platform! I can get any problem solved here!");
}
then EditText should show in the exact same way. Like shown in the below image
screenshot
Dots at the end of the line denotes that it should be scrollable horizontally.
I tried this
<EditText
android:layout_below="#id/label_code"
android:id="#+id/et_code"
android:layout_width="match_parent"
android:layout_height="400dp"
android:inputType="textNoSuggestions|textMultiline"
android:gravity="top"
android:scrollHorizontally="true"
android:background="#drawable/square_border_unselected"
android:padding="15dp" />
But in that case, horizontal scroll is not working. The text is going to next line if it's length is more than screen size.
Is there any solution to implement all three features in EditText?
Edit #1:
If I don't use textMultiline than I am able to achieve horizontally scrollable EditText
Update #1
This is not the perfect solution but through this I achieved what I wanted.
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="wrap_content"
android:minEms="1000"
android:layout_height="wrap_content"
android:minHeight="250dp"
android:inputType="textNoSuggestions|textMultiLine"
android:gravity="top"
android:padding="15dp" />
</HorizontalScrollView>
android:inputType="text" will do the job for you!
<EditText
android:text="This is an awesome platform! I can get any problem solved here!"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#876"
android:imeOptions="actionDone"
android:inputType="text"
android:paddingLeft="2dp"
android:textColor="#FFFFFF"/>
EDIT: Here goes what you want! Horizontal scroll with multi line.
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#876"
android:paddingLeft="2dp"
android:text="This is an awesome platform! I can get any problem solved here!"
android:textColor="#FFFFFF" />
</HorizontalScrollView>
out put:
EDIT3 : This is nothing but because you are lazy.Adjust bounds like below!
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:background="#789"
android:inputType="textMultiLine"
android:layout_width="500dp"
android:layout_height="200dp"
android:textColor="#FFFFFF" />
</LinearLayout>
</HorizontalScrollView>
Cheers!
Try this:
android:scrollbars = "vertical"
in your EditText xml.
try these lines in your edittext
android:inputType="textMultiLine"
android:maxLines="10"
android:scrollbars="vertical"
Try putting your editText in a scroll view
The combination of XML attributes that removed both the Suggestions and the Suggestions Bar while retaining multi-line text was the following:
android:privateImeOptions="nm"
android:inputType="textNoSuggestions | textMultiLine"
or
android:privateImeOptions="nm"
android:inputType="textFilter | textMultiLine"
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>
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.
I have this layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="#dimen/activity_horizontal_margin" >
<LinearLayout
android:id="#+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
What i want is when the user enters more text than which fits into a single line, the EditText wraps the line, increases it height automatically and shows the not fitting text in the next line. The EditText should not be scrollable horizontally.
I read lots of questions related to this, but none of them helped. Currently the EditText above does not wrap the lines, and can be scrolled horizontally. I tested on Android 4.2 and 4.4.
EDIT: added complete layout.
EDIT2:
Sorry, this is my fault. I change the input type programatically in my code:
mEditText.setInputType(mInputTypes.get(question.getType()));
So with this line, i have overriden the input type from xml. I modified the code, and the multiLine input type indeed works.
I have removed all unnecessary attributes and put only required attribute android:maxLines="20",
So it looks like this,
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:maxLines="20" />
add android:scrollHorizontally="false" and android:inputType="textMultiLine" this attribute in EditText from this post on SO
<EditText
android:id ="#+id/editText"
android:layout_width ="0dip"
android:layout_height ="wrap_content"
android:layout_weight ="1"
android:inputType="textCapSentences|textMultiLine"
android:maxLines ="4"
android:maxLength ="2000"
android:scrollHorizontally="false" />
The only solution that worked for me:
EditText someedittext = (EditText)findViewById(R.id.someedittext);
someedittext.setMaxWidth(someedittext.getWidth());
I need to show a large number of EditText controls on a screen, each of which will only allow entering 0-2 digits. The default EditText size is too wide for me to show enough EditText controls on a screen, but I have been unable to figure out how to make them narrower. I have tried the following attributes in
XML:
android:maxLength="2"
android:layout_width="20dip"
android:maxWidth="20px"
android:ems="2"
android:maxEms="2"
So the question is: how can EditText be made smaller than default?
Try this way instead, shows the difference. Use the layout_width with the specified width.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:width="10dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello"
/>
<EditText
android:layout_width="40dip"
android:layout_height="wrap_content"
android:text="#string/hello"
android:maxLength="2"
/>
</LinearLayout>
Hey once you try this,it may work.......
android:textAppearance="?android:attr/textAppearanceSmall"
In case you end up on this page to search how to achieve the same in Java code..
txtSample.setFilters(new InputFilter[]{new InputFilter.LengthFilter(2)});
When in a table, as you describe, android:layout_gravity="left" will collapse the EditText to to the stated size of the EditText