Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can we use a EditText for creating hyperlinks?

 
Ranch Hand
Posts: 48
1
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 48
1
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 48
1
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic