0

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?

George
  • 5,808
  • 15
  • 83
  • 160

1 Answers1

2

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.

tomato
  • 3,373
  • 1
  • 25
  • 33
  • :Ok,if i just create "http://www.google.gr" it works.But how will i add a text?Sorry if i didn't understand what you say. – George Jan 23 '12 at 10:32
  • Just declare two string resources: one for your `URL` (containing google.gr), and one for the text to go in the `TextView` (containing "Check here"). – tomato Jan 23 '12 at 10:37
  • :Now it shows me the "Check here "but it's not clickable.I added in read.class "TextView icons_link=(TextView) findViewById(R.id.icons_link);",where the "icons_link" is the id from the textview. – George Jan 23 '12 at 10:49
  • What is it you are trying to do here? Do you simply want to redirect the user to a Google webpage (in the browser) when they click your `TextView`? If so, look at http://stackoverflow.com/questions/2734270/how-do-i-make-links-in-a-textview-clickable for the correct approach. – tomato Jan 23 '12 at 10:53
  • :Ok,i used the above (the textview).I couldn't do it the way i wanted ,but its ok.Thanks a lot (accepted and voted). (if you could help me with this "http://stackoverflow.com/questions/8954682/android-how-to-manipulate-array-list-plot-is-wrong" also,i 'll appreciate it.Thanks! – George Jan 23 '12 at 12:05