简体   繁体   中英

For setting limit in multiline edittext 's each line

I want to set limits in edittext each line and then click enter key cursor move to the next line in android studio, please answer how can I do this..my codes are

<EditText
      android:inputType="textMultiLine|number"
      android:singleLine="false"
      android:digits= "0,1,2,3,4,5,6,7,8,9"
      android:id="@+id/number"
      android:hint="Enter Number Here..."
      android:paddingLeft="10dp"
      android:textSize="15sp"
      android:fontFamily="sans-serif"
      android:layout_margin="5dp"
      android:gravity="top|left"
      android:background="#ffffff"
      android:layout_width="match_parent"
      android:layout_height="130dp" />

when I click enter key it did not work and when I remove inputType from XML code enter key works please solve

Follow steps below:

Step 1: add these lines in your XML

android:maxLines="1"
android:imeOptions="actionNext"

Step 2(optional): use following code in your Activity

If you want to do some action when user clicks next

editText.setOnEditorActionListener((v, actionId, event) -> {
    if (actionId == EditorInfo.IME_ACTION_NEXT) {
        //your code here
        return true;
    }
    return false;
});

I m using AndroidX with Java 1_8 enabled

Hope this will help!

May be you need to use android:minEms or android:maxEms . Read more in following link:

https://developer.android.com/reference/android/widget/EditText

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM