2011-07-14 4 views
5

私が開発しているアンドロイドアプリにハイパーリンクを貼りたい。 android appのウェブサイトへのハイパーリンクの配置方法は?

が、私はこの試みた: http://google.comと:

main.xml

<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

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

しかし、問題があり、リンクは次のようになります私は実際のURLを表示したくありません。

1)「Googleにアクセスするにはここをクリックしてください」というテキストでリンクを置き換える方法、テキストはウェブサイトのURLにリンクされていますか?私も試した電子メールアドレス(「をメールで送信するには、ここをクリック」とテキストが[email protected]とリンクしなければならないなどのテキスト何かでそれを置き換えるために、どのように同じ質問、)


を配置する方法

2)このチュートリアル:http://coderzheaven.com/2011/05/10/textview-with-link-in-android/

しかし、私は次のエラーメッセージを取得しています:

Description Resource Path Location Type 
http cannot be resolved to a variable MyLink.java /MyLink/src/com/MyLink line 21 Java Problem 
Syntax error on token "" <br /> <a href="", ? expected after this token MyLink.java /MyLink/src/com/MyLink line 21 Java Problem 
Type mismatch: cannot convert from String to boolean MyLink.java /MyLink/src/com/MyLink line 20 Java Problem 

答えて

10

使用トン彼はデフォルトのLinkify classです。ここで

Exampleとチュートリアルからコードです:

これは私がこれはあなたの問題を解決すると思います、あなたのための私のサンプルコードです:このチュートリアルについて

public class StackOverflowActivity extends Activity { 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    // 1) How to replace link by text like "Click Here to visit Google" and 
    // the text is linked with the website url ? 
    TextView link = (TextView) findViewById(R.id.textView1); 
    String linkText = "Visit the <a href='http://stackoverflow.com'>StackOverflow</a> web page."; 
    link.setText(Html.fromHtml(linkText)); 
    link.setMovementMethod(LinkMovementMethod.getInstance()); 
    // 2) How to place email address 
    TextView email = (TextView) findViewById(R.id.textView2); 
    String emailText = "Send email: <a href=\"mailto:[email protected]\">Click Me!</a>"; 
    email.setText(Html.fromHtml(emailText)); 
    email.setMovementMethod(LinkMovementMethod.getInstance()); 
} 

}

+0

方法(私はそれを動作させようとしていますが、エラーメッセージが表示されています:[http://coderzheaven.com/2011/05/10/textview-with-link-in-android/](http://coderzheaven.com/ 2011/05/10/textview-with-link-in-android /) - 上記を参照してください、私の投稿を更新しました – super

+1

私はあなたのJavaを表示していないコードなので、何が問題なのか分かりません。私の意見では、 ""を ""に変更する必要があります。上記の作業サンプルコードを添付して、このコードを試してみてください。 – kameny

+0

ありがとうございました – super

関連する問題