0

新しいアクティビティを開始させるために、TextViewへのリンクを挿入しようとしています。Utils私はそれを行うためにクラスにメソッドを書きました:

public static final String tagPattern = "#([^ ]+)";
public static final String tagReplace = "<a href=\"org.openihs.seendroid://display/tag/$1/\">#$1</a>";
public static final String userPattern = "@([^ ]+)";
public static final String userReplace = "<a href=\"org.openihs.seendroid://display/user/$1/\">@$1</a>";
static public void linkify(TextView view) {
    String text = view.getText().toString();
    text = text.replaceAll(Utils.tagPattern, Utils.tagReplace);
    text = text.replaceAll(Utils.userPattern, Utils.userReplace);
    view.setMovementMethod(LinkMovementMethod.getInstance());
    view.setText(Html.fromHtml(text));
    Log.d("SeenDroid", text);
    Linkify.addLinks(view, Linkify.ALL);
}

(logcatへの)出力例は次のとおりです。

foo <a href="org.openihs.seendroid://display/tag/bar/">#bar</a> baz http://google.fr/

また、実際のUIはhttp://google.fr/をリンク(予期される動作)として提供しますが#bar、通常のテキスト(予期しない動作)として提供します。

TextViewはListViewにあります。

その問題を解決するためのアイデアはありますか?

よろしく、ProgVal

4

2 に答える 2

0

交換は行わないでください。Html.fromHtmlすでにタグを適切に処理しています。

于 2011-11-29T19:34:25.093 に答える
0

Linkifyの動作は、使用しようとしている方法とは少し異なります。

public static final String AUTHORITY = "your_package.your_content_provider";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/tag/");
Pattern pattern = Pattern.compile(tagPattern);
Linkify.addLinks(view, pattern, CONTENT_URI.toString());

CONTENT_URIは、マニフェストに登録したContentProviderを指します。

于 2011-11-29T22:15:25.113 に答える