George
George

Reputation: 5691

android -- how to make my text 'clickable' (url link)

My problem is that when i add the string "Check here" then the link isn't clickable.

If i only leave <a href ="http://www.google.gr" > ,then it works ok.

I have in the read.class:

public class read extends Activity {

     /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.read);

        String myFeed=getResources().getString(R.string.icons_link_str);

        try{
            URL url =new URL (myFeed);

            URLConnection connection=url.openConnection();
            HttpURLConnection httpConnection =(HttpURLConnection)connection;

            int responseCode=httpConnection.getResponseCode();
            if (responseCode ==HttpURLConnection.HTTP_OK){
                InputStream in = httpConnection.getInputStream();

            }
        }
        catch (MalformedURLException e) {}
        catch (IOException e) {}

    }

}

in the read.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >


    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/choose_help"
         />

    <TextView
                android:id="@+id/icons_link"
                android:autoLink="web"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:linksClickable="true"
                android:text="@string/icons_link_str"/>



</LinearLayout>

and in the strings:

<string name="icons_link_str"><a href ="http://www.google.gr" >Check here.</a></string>

Can i do sth for that?

Upvotes: 0

Views: 4629

Answers (1)

tomato
tomato

Reputation: 3393

You problem is that...

new URL(myFeed) 

is actually effectively the same as...

new URL("<a href =\"http://www.google.gr\" >Check here.</a>");

i.e. the URL class knows nothing about parsing HTML anchor tags and so the string makes no sense. What it expects to receive is just the http://www.google.gr URL.

I suggest you create a separate <string> for just the URL and use this with your HTTP code.

Upvotes: 2

Related Questions