Hyperlink to a web site

Put your problem here if it does not fit any of the other categories.

Hyperlink to a web site

Postby soor » Thu Jan 27, 2011 12:04 pm

Greetings,

in main.xml, I have a hiperlink to a wabsite. The problem is, that the text is the same as the URL. For example: If I set the URL to http://www.google.com, the text on the screen, will be the same.
But I would like to have: text on the screen --> LINK, URL to show up --> http://www.google.com.

My Code is:

Java
Code: Select all
import android.app.Activity;
import android.os.Bundle;
import android.text.util.Linkify;
import android.widget.TextView;

public class WebLink extends Activity
{
@Override

public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView textview = (TextView) findViewById(R.id.hyperlink);
Linkify.addLinks(textview, Linkify.WEB_URLS);
}
}


main.xml
Code: Select all
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/hyperlink"
android:id="@+id/hyperlink"
android:autoLink="web"
>
</TextView>


strings.xml
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">WebLink</string>
<string name="hyperlink">http://google.com</string>
</resources>


Can someone please help me?
Thanx, and have a nice day.
soor
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sun Oct 24, 2010 6:56 pm

Top

Re: Hyperlink to a web site

Postby Chitra » Tue Feb 08, 2011 2:13 pm

Hello,

Try this code in ur's java class

Code: Select all
TextView tv_privacy = (TextView) findViewById(R.id.urText);
SpannableString content = new SpannableString(tv_privacy.getText());
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
tv_privacy.setText(content);
tv_privacy.setOnClickListener(this);
Thanks,
Chitra
User avatar
Chitra
Master Developer
Master Developer
 
Posts: 213
Joined: Mon Mar 01, 2010 7:59 am
Location: Bangalore

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google Feedfetcher and 19 guests