2012-01-22 12 views
0

私の問題は、「ここにチェック」という文字列を追加するとリンクがクリックできないということです。android - 私のテキストをクリック可能にする方法(URLリンク)

私は<a href ="http://www.google.gr" >のままにしておけば、正常に動作します。

私はread.classを持っている:

read.xmlで
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) {} 

    } 

} 

<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> 

と文字列で:

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

は私はそのためSTH行うことができます?

答えて

2

あなたの問題があること...

new URL(myFeed) 

は、実際には実質的に同じである... URLクラスすなわち

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

は、HTMLのアンカータグなどの文字列になりを解析について何も知りませんも意味ない。受信すると予想されるのは、http://www.google.gr URLです。

URLだけに別の<string>を作成し、これをHTTPコードで使用することをおすすめします。

+0

:「 http://www.google.gr "を作成しても問題ありません。テキストを追加するにはどうすればよいですか?申し訳ありませんが、いう。 – George

+0

'URL'(google.grを含む)と' TextView'( "ここにチェックする")を含むテキストの2つの文字列リソースを宣言するだけです。 – tomtheguvnor

+0

:ここでは「ここにチェック」が表示されますが、クリック可能ではありません。「iconView」のIDは、「icon_link」のIDであるread.class「TextView icons_link =(TextView)findViewById(R.id.icons_link)テキストビュー。 – George

関連する問題