0

I have an EditText that I am trying to set with a very long, unbreaking text value (a URL), but even with the following XML declaration, the text is breaking to a second line.

<EditText 
android:id="@+id/address" 
android:layout_width="wrap_content" 
android:layout_height="match_parent"
android:layout_weight="1"
android:maxLines="1"
android:hint="Enter URL"
android:text="http://www.example.com/news/2010-07-15/this-is-the-story-title-here.html">
</EditText>

I've tried the solutions here (adding android:ellipsize="end"), but it made no difference. Reducing the text in length to something no more than the length of the EditText worked... but this is realistic for a URL EditText.

Any suggestions?

Thanks,

Paul

Unpossible
  • 10,607
  • 22
  • 75
  • 113

3 Answers3

5

Set

android:scrollHorizontally="true"
Unpossible
  • 10,607
  • 22
  • 75
  • 113
Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
  • android:scrollHorizontally seemed to do it. Any idea how to NOT have the EditText selected by default with the cursor at the end when an Activity is started via XML? – Unpossible Jul 20 '11 at 20:12
  • 1. you should accept my answer 2. you could have another view in the layout and request focus to it.. – Manfred Moser Jul 20 '11 at 20:27
  • Well I wasn't sure that it was the 'most correct one' that was going to come in, as it suggests using a deprecated property, and the results include the text in the EditText being scrolled all the way horizontally to the end, which is less than optimal. – Unpossible Jul 20 '11 at 20:34
  • If you want to edit the answer to remove the android:singleLine property, I can mark it as the answer for now. – Unpossible Jul 20 '11 at 20:35
2

Have you tried adding android:singleLine="true" to the mix

<EditText 
android:id="@+id/address" 
android:layout_width="wrap_content" 
android:layout_height="match_parent"
android:layout_weight="1"
android:singleLine="true"
android:maxLines="1"
android:hint="Enter URL"
android:text="http://www.example.com/news/2010-07-15/this-is-the-story-title-here.html">
</EditText>
Otra
  • 8,108
  • 3
  • 34
  • 49
  • android:singleLine is deprecated, per http://developer.android.com/reference/android/R.attr.html#singleLine – Unpossible Jul 20 '11 at 20:04
  • 1
    Interesting, google seems to have conflicting docs. It is not listed as deprecated here. http://developer.android.com/reference/android/widget/TextView.html#attr_android%3asingleLine Perhaps they should update it. In the mean time, does setting scroll horizontally to true help? – Otra Jul 20 '11 at 20:10
1

Use value for the attribute inputType other than textMultiLine. The attribute singleLine is deprecated.

spgodara
  • 984
  • 9
  • 10