Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can we use a EditText for creating hyperlinks?

 
Vishal Srivastav
Ranch Hand
Posts: 46
Android Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

We can use a TextView for adding hyperlinks to it by various methods, like using the attribute autoLink, or by using setMovementMethod().

Can we do the same using and EditText widget? I am trying to create a notepad, in which if any such text entered, like url, email, number or something similar, we should get a hyperlink to click on it and open the browser.

Please help.

Thanks All.
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An EditText implies that the user is editing the text; having some words as active links at that moment would be a hindrance to editing. Think about what would happen if a user clicked a word that was an active link - how would he edit it?

Editing (using an EditText) and display (using a TextView) should be separate activities (in the non-Android sense of the word).
 
Vishal Srivastav
Ranch Hand
Posts: 46
Android Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lester Burnham wrote:An EditText implies that the user is editing the text; having some words as active links at that moment would be a hindrance to editing. Think about what would happen if a user clicked a word that was an active link - how would he edit it?

Editing (using an EditText) and display (using a TextView) should be separate activities (in the non-Android sense of the word).


I agree with this. But the thing is, in the same version of application being developed on iPad, it is successfully done. Going with the same concept, even in MS Word, this is easily done. Whenever a any such text is written, it automatically changes to a hyperlink!!!

I have been trying it today but have not been able to do it. It is the requirement of the application...
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not saying that it can't be done; I'm saying that it's not necessarily a good idea, no matter what other apps do, or what the requirements say.

Irrespective of that, if you still want to do it you'll probably have to write a fair amount of code that does this for you. The android.text.util.Linkify class will likely play a role, as will classes like android.text.Spannable, SpannableString and SpannableStringBuilder.
 
Vishal Srivastav
Ranch Hand
Posts: 46
Android Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have used Linkify. Not a success till now. Got the hyperlink when used autoLink attribute in XML layout, but link is not being created when manually a type of hyperlink text is written. I am trying for it.

And I agree with the fact that it will really be annoying for the user to create this thing in EditText.

Thanks for your help. Will reply back when successful
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic