EditText word wrap - android

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());

Related

How to make TextInputLayout with two edit fields and only one hint?

Additional constraints: both edit fields are placed to each other horizontally and the hint is long enough to be above them
Long enough hint above two edit fields
======= ==================
enter image description here
It's impossible for TextInputLayout to have 2 EditText as children. Doing this throws you an InflateException like this :
android.view.InflateException: Binary XML file line #xxx: We already
have an EditText, can only have one
So I assume that it's a Material Design guideline, and having one TextInputLayout with 2 EditText is anti-pattern to google's recommandations.
Try this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000"
android:gravity="center"
android:text="Only one hint above two edit fields"
android:textSize="20dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/et1"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/et2"
/>
</LinearLayout>
</LinearLayout>
If you ant to hide the TextView, you can use a TextChangedListener and set the Visibilty to INVISIBLE if the text equals "".

How to make edittext scrollable, multiline and turn off auto suggest?

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"

cant type in an EditText android

I have this xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/horizontalPadding"
android:paddingRight="#dimen/horizontalPadding"
android:paddingTop="#dimen/verticalPadding"
android:paddingBottom="#dimen/verticalPadding">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:padding="#dimen/padding" >
<TextView
android:text="#string/training_exercise_set_weight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/training_exercise_set_weight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="numberDecimal"
android:ems="10" />
</LinearLayout>
</LinearLayout>
When my app is running the keyboard is visible and clickable, but the value of editText doesn't change. how can i resolve it?
If someone is interesed, i resolved using the EditText.requestFocus()
Try to replace android:ems="10" with android:maxEms="10" or android:maxLength="10", I'm not sure, what you want to achieve with this parameter
Hope, this will solve you issue
android:ems="10" is all about width of the view, however you are overriding this setting by layout_width property setting to match_parent.
It looks like you would want two EditTexts to be stretch equally and fill that LinearLayout, so here you wouldn't need ems at all. You would need maxLength instead.
Also note that to stretch those EditTexts you should set their widths to 0dp and set their weight to 1 (or something else. They should be equal).
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:padding="#dimen/padding" >
<TextView
android:text="#string/training_exercise_set_weight"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/training_exercise_set_weight"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="numberDecimal"
android:maxLength="10" />
</LinearLayout>
For me, the problem was, I didn't let my PopupWindow be focused. Then I found out that my PopupWindow focusable was by default set to false. So, I try to add 1 new parameter that explicitly tells the PopupWindow is focusable. You can see it in my screenshot below. Previously I didn't pass the false value, only the first three values.
Now, I can type anything in the EditText. This one took a whole day to be resolved. 🤣

Android Title bar gets pushed up when edit text content increases

I have a relative layout which contains only the edit text view. But when content of edittext increases, my title bar gets shifted upwards. Most of the solutions I went through addresses the issue of shifting title bar when keyboard pops out. But I didn't found anything in case its content increases. I also used android:isScrollContainer="false" as suggested in this post How to avoid soft keyboard pushing up my layout?, but still the same issue. Is there a way to prevent it? Here is my xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroll_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="false"
android:background="#drawable/background" >
<EditText
android:id="#+id/hidden_edit_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:imeOptions="flagNoExtractUi"
android:inputType="textMultiLine"
android:singleLine="false"
android:paddingLeft="10sp"
android:paddingTop="5sp"
android:paddingRight="5sp"
android:scrollbars="vertical"
android:background="#android:color/transparent"
android:textSize="26sp" >
</EditText>
</RelativeLayout>
I managed to solve this issue by putting edittext in scrollview and replacing adjustPan with adjustSize in the manifest. This is the final working layout
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background">
<EditText
android:id="#+id/hidden_edit_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:imeOptions="flagNoExtractUi"
android:inputType="textMultiLine"
android:paddingLeft="10sp"
android:paddingRight="5sp"
android:paddingTop="5sp"
android:singleLine="false"
android:textSize="25sp" >
</EditText>
</ScrollView>
try to run your code after removing :
android:background="#android:color/transparent"
make your relative layout height and width to wrap_content.......... probably works. since when text increases your complete layout shifts. Try it and please rpy
Usually this can be solved by adding the android:windowSoftInputMode="adjustPan" property to your activity in the AndroidManifest file.

cannot see button next to search box android

I'm having trouble when showing a button next to the search box. I'm using an auto complete text view and i don't know if this is due to the auto complete text view. How can i fix this. Here's what i got so far:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<AutoCompleteTextView
android:id="#+id/autocomplete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text"
/>
<Button
android:id="#+id/search_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go"
/>
</LinearLayout>
To fix this, just add the tag android:layout_weight=1 to your AutoCompleteTextView.
This happens because android noticed you set the layout_width to fill_parent on your AutoCompleteTextView, and then it has no space for the Button left. Setting the weight to 1 means the textview will be "generous" and give as much space to any other components as they request, which in this case is limited to the width of the Button after is wrapped.
You are filling the parent width with your AutoCompleteTextView (thus pushing the Button out of screen width). Try to change this
<AutoCompleteTextView
android:id="#+id/autocomplete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text"
/>
into this
<AutoCompleteTextView
android:id="#+id/autocomplete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="text"
/>
And your Button should become visible. Here is a nice resource conserning layouts: Android Developer | Declaring Layouts

Categories

Resources