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 9242199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:32:00+00:00 2026-06-18T08:32:00+00:00

I want to allow use to enter just 5 lines, I tried this <EditText

  • 0

I want to allow use to enter just 5 lines, I tried this

<EditText
    android:layout_below="@+id/tv_signup_descriptionError"
    android:id="@+id/et_signup_description"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dip"
    android:hint="@string/et_hint_enterDescription"
    android:singleLine="false"
    android:lines="5"
    android:gravity="top"
    android:scrollHorizontally="false"
    android:inputType="textMultiLine" 
    android:maxLines="5"/>

but still I can press Enter after the fifth line

  • 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-18T08:32:02+00:00Added an answer on June 18, 2026 at 8:32 am

    You cannot do that using any XML attributes.

    maxlines represents the maximum height of the EditText and not the number of input lines.

    You can however implement your own code to check for the number of lines.

    The following is not my own code, but is taken from this answer.

    mEditText.setOnKeyListener(new View.OnKeyListener() {
    
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
    
                // if enter is pressed start calculating
                if (keyCode == KeyEvent.KEYCODE_ENTER
                        && event.getAction() == KeyEvent.ACTION_UP) {
    
                    // get EditText text
                    String text = ((EditText) v).getText().toString();
    
                    // find how many rows it cointains
                    editTextRowCount = text.split("\\n").length;
    
                    // user has input more than limited - lets do something
                    // about that
                    if (editTextRowCount >= 7) {
    
                        // find the last break
                        int lastBreakIndex = text.lastIndexOf("\n");
    
                        // compose new text
                        String newText = text.substring(0, lastBreakIndex);
    
                        // add new text - delete old one and append new one
                        // (append because I want the cursor to be at the end)
                        ((EditText) v).setText("");
                        ((EditText) v).append(newText);
    
                    }
                }
    
                return false;
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

customers does not want to allow user to use back or forward button. Just
I want to allow the user to use lowercase or uppercase letters giving the
I want to allow my shared hosting sites to use MongoDB, however as they
I want to use Event Aggregator to allow communication between presenters on the page.
In short, I want to use an object literal to allow me to pass
The use case is simple. I allow users to enter in an expiration field
I want to create an android application that a user can use to text
We have a high security application and we want to allow users to enter
I want to allow the interface to change only if the flag enableRotation=1. I’ve
I want to allow user to upload a file of txt ,doc or pdf

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.