1

I am working on edit text, by entering some text then go to enter key on the soft keyboard it will go to next line again pressing enter it will go to the third line finally the resultant text of edit text should be consists of three line with spaces.

How can Ii get that result in a single line?

Any help would be appreciated.

KishuDroid
  • 5,411
  • 4
  • 30
  • 47

3 Answers3

1

Make android:singleLine="true" in xml file is the proper way.

  <EditText
     android:id="@+id/editText1_1"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:singleLine="true"
     android:ems="10" > 

But still, if you want to type multiple line in edittext and print it(display it) in a single line do as below(it is not the perfered way, but you need so do it like below)

String editTextVal =(EditText)findViewById(R.id.editText1_1)).getText().toString();
Log.d("in single Line", Html.fromHtml(editTextVal.replace("\n", " ")).toString());

Try this.

Note : Remove android:singleLine="true" from xml for muliple line.

ShahiM
  • 3,179
  • 1
  • 33
  • 58
Abin Antony
  • 119
  • 1
  • 5
0
<EditText
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:padding="5dp"
        android:hint="Add text here"
        android:gravity="left|center"
        android:singleLine="true"/>
Suhas Bachewar
  • 1,230
  • 7
  • 21
0

If you want to make your EditText to restrict to Single Line then Use below line:

1) Include android:singleLine="true" to your EditText.

And If you want to get EditText's value OnKeyBoard click then do following:

2) Use editText.setImeOptions(EditorInfo.IME_ACTION_DONE);

OR

3) Include android:imeOptions="actionDone" to your EditText.

KishuDroid
  • 5,411
  • 4
  • 30
  • 47