Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7947773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:31:44+00:00 2026-06-04T01:31:44+00:00

If I set SingleLine=true on an EditText widget, I get a single-line edit control

  • 0

If I set SingleLine=true on an EditText widget, I get a single-line edit control that doesn’t allow hard returns to be inserted by the user (clicking Enter moves to the next field instead of inserting a new line). If I don’t set SingleLine=true, the user can insert hard returns.

If I set layout_height=”wrap_content”, the EditText control will grow vertically to show all of the text. However, it only does this if SingleLine is not set to true.

So, my question is, is it possible to get the word-wrapping and vertical resizing, without allowing the user to enter hard line breaks? I guess I could trap the enter keypress, but then I would also have to catch other ways they might get one in there (copy/paste, not sure what else?). Is there a simple way to do this with just the right combination of properties?

I prefer the word-wrap where the user can see all of the text, compared to the horizontal scrolling of a single-line edit control, but I don’t really want them thinking they can enter multiline text (and I don’t want to have to support it). I guess I might just convert hard returns to spaces when I save the data to my database, if I have to (the legacy app I sync this data to on the PC can’t handle hard returns).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:31:47+00:00Added an answer on June 4, 2026 at 1:31 am

    I too was looking for something to do this as well. The only solution I found was to extend the EditText as follows:

    package com.kylemilligan.test;
    
    import android.content.Context;
    import android.util.AttributeSet;
    import android.view.inputmethod.EditorInfo;
    import android.view.inputmethod.InputConnection;
    import android.widget.EditText;
    
    public class NoNewlineEditText extends EditText
    {
    
        public NoNewlineEditText(Context context) {
            super(context);
        }
    
        public NoNewlineEditText(Context context, AttributeSet attributeSet) {
            super(context, attributeSet);
        }    
    
        @Override
        public InputConnection onCreateInputConnection(EditorInfo outAttrs)
        {
            InputConnection connection = super.onCreateInputConnection(outAttrs);
            int imeActions = outAttrs.imeOptions & EditorInfo.IME_MASK_ACTION;
            if ((imeActions & EditorInfo.IME_ACTION_DONE) != 0)
            {
                // clear the existing action
                outAttrs.imeOptions ^= imeActions;
                // set the DONE action
                outAttrs.imeOptions |= EditorInfo.IME_ACTION_DONE;
            }
            if ((outAttrs.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0)
            {
                outAttrs.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION;
            }
            return connection;
        }
    }
    

    And then in XML use like:

            <com.kylemilligan.test.NoNewlineEditText
                android:id="@+id/noNewLineText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="top|left"
                android:imeOptions="actionDone"
                android:minLines="5" />
    

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For setting the Single Line in EditText we use android:singleLine=true but I want to
Set content of table ... ViewState[Table1] = Table1; // When remove this line, table
I set up the basic Authentication/Authorization set up, but a problem now is that
I set up a hitcounter so that each time someone goes to my site,
In my windows phone 7 App I have a single line textbox. When the
I've seen a few other questions dealing with localization but that doesn't seem to
I have a (single line) TextCtrl. The user types data into this. When they
I have a multi-link postal address EditText widget which is declared as below: <EditText
my xml code is <TextView android:layout_width=fill_parent android:layout_height=wrap_content android:layout_gravity=center_vertical android:lines=1 android:singleLine=true android:textColor=#ffffff android:focusable=true android:marqueeRepeatLimit=marquee_forever android:ellipsize=marquee
I have set a hint for an EditText , currently the hint visibility is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.