is it possible multiline with input type as number

2019-02-14 02:35发布

问题:

When the android edittext input type is number, is it possible to make multilines? I have tried with the following in xml file.

android:inputType="number|textMultiLine"

But it did not work. Is it not possible to make multiline when the input type is number?

Please help me in this. Thank you.

回答1:

Please do this:

android:inputType="textMultiLine|number"
android:digits="0,1,2,3,4,5,6,7,8,9"

Taken from here: Answer



回答2:

I tried each and every solution for your problem.The thing is that when you try to use android:inputType attribute with number android doesnot provide textMultiLine feature for users.it is possible with only one attribute i.e., android:numeric="integer".I know that it is Deprecated but for your problem this is the only solution.

I have made a sample xml file.it is as follows:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:gravity="top"
        android:lines="10"
        android:numeric="integer" />

    <EditText
        android:id="@+id/editText3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:maxLines="10"
        android:numeric="integer" />

    <EditText
        android:id="@+id/editText4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:maxLines="10"
        android:numeric="integer" />

</LinearLayout>

There are sample EditText used with explanation as follows:-

The first one describes the TextView be exactly this many lines tall by using the attribute-android:lines="10".Here if you donot provide android:gravity="top" then any input you do will start from the center of the EditText.

The second one describes the TextView be at most this many lines tall by using the attribute-android:maxLines="10".

I hope you will finally be happy for your problem being solved successfully.