0

I'm using a Edit Text to put in a URL to search in the Internet. But to use a URL, I need to put http:// in front of the Url. Is there a way, to hide this and use it for default?

And the other thing is to have only one single line in the Edit Text?

Thanks

1 Answers1

0

Is there a way, to hide this and use it for default?

When you retrieve the value from the EditText, see if it begins with a recognized scheme (e.g., https://). If not, add it yourself, through string concatenation or StringBuilder or something.

And the other thing is to have only one single line in the Edit Text?

Use android:maxLines="1" in the <EditText> element in your layout.

Community
  • 1
  • 1
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Could you give me an example of the first? – Arved Vihweger May 31 '15 at 14:33
  • @ArvedVihweger: Only if you explain, **completely and precisely**, what you do not understand. Checking to see if a string begins with another string in Java is very simple, using [the `startsWith()` method](http://developer.android.com/reference/java/lang/String.html#startsWith%28java.lang.String%29). – CommonsWare May 31 '15 at 14:38
  • Yes, could you give me an example how to use the startsWith() method? – Arved Vihweger May 31 '15 at 15:05
  • @ArvedVihweger: Given an `EditText` named `url`, `url.getText().toString().startsWith("https://")` will return `true` if the contents of the `EditText` begins with `https://`. – CommonsWare May 31 '15 at 15:11
  • When I try to use this, it's the same like before. I have to enter http:// to load a URL in the WebView. – Arved Vihweger May 31 '15 at 15:59
  • @ArvedVihweger: And, if you read my answer, you will see that I wrote "If not, add it yourself, through string concatenation or StringBuilder or something", where "it" is the scheme. – CommonsWare May 31 '15 at 16:00