2017-03-06 50 views
-2

我試着設置我的EditText來多一次,它的工作。但是當我在EditText上改變了一些東西使它看起來有點酷時,它不再輸入多行。如何將Edittext設置爲多行?

<EditText 
     android:ems="10" 
     android:inputType="textMultiLine" 
     android:text=" " 
     android:id="@+id/reqdesc" 
     android:layout_width="fill_parent" 
     android:layout_height="110dp" 
     android:hint=" Enter your request here" 
     android:textSize="18sp" 
     android:maxLength="80" 
     android:background="@layout/rounded_border_edittext" 
     android:lines="8" 
     android:minLines="2" 
     android:gravity="top|left" 
     android:maxLines="4" 
     android:layout_marginTop="14dp" 
     android:layout_below="@+id/post" 
     android:layout_alignParentStart="true" /> 
+0

這大概:'機器人:layout_height = 「110dp」'。讓它'wrap_content' –

+0

嘗試刪除'ems'。 – Wizard

+0

@R.Zagórski:它仍然不起作用 – LMae

回答

0
reqdesc = (EditText) myView.findViewById(R.id.reqdesc); 
reqdesc.setInputType(InputType.TYPE_CLASS_TEXT | 
      InputType.TYPE_TEXT_FLAG_MULTI_LINE | 
      InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); 
InputFilter[] fArray = new InputFilter[1]; 
    fArray[0] = new InputFilter.LengthFilter(maxLength); 
    reqdesc.setFilters(fArray); 

現在的工作,我把代碼的這些線路的onCreate下。

0

試試這個:

找到你Edittext

etReqdesc = (EditText) findViewById(R.id.reqdesc); 

現在programetically撥打:內onCreate()

etReqdesc.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE); 
etReqdesc.setSingleLine(false); 
etReqdesc.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION); 

您的EditText應該是這樣的:

<EditText 
    android:ems="10" 
    android:inputType="textMultiLine" 
    android:text=" " 
    android:id="@+id/reqdesc" 
    android:layout_width="fill_parent" 
    android:layout_height="110dp" 
    android:hint=" Enter your request here" 
    android:textSize="18sp" 
    android:background="@layout/rounded_border_edittext" 
    android:gravity="top|left" 
    android:layout_marginTop="14dp" 
    android:layout_below="@+id/post" 
    android:layout_alignParentStart="true" /> 

刪除android:maxLength="80"屬性。

+0

感謝,但它不工作:( – LMae

+0

@LMae檢查編輯.... – rafsanahmad007

+0

如何以編程設置的最大長度是多少? – LMae