6

以前の質問に続いて、カスタムでハイパーリンクを管理する際にまだ問題がありますAlertDialogが、カスタム ダイアログであるために機能しないだけだと思う​​ので、問題を絞り込んだと思います。

ここここのすべての指示に従いましたが、この状況を回避できないようです

私はこのstrings.xmlように定義された文字列を持っています:

<string name="link_text_manual"><b>text2:</b> This is some other
  text, with a <a href="http://www.google.com">link</a> specified
  via an &lt;a&gt; tag.  Use a \"tel:\" URL
  to <a href="tel:4155551212">dial a phone number</a>.
</string>

この方法でダイアログを作成すると:

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Data")
        .setIcon(R.drawable.info)
       .setMessage(R.string.link_text_manual)
       .setCancelable(true)
       .setNegativeButton("OK", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();
           }
       });

AlertDialog welcomeAlert = builder.create();
welcomeAlert.show();
// Make the textview clickable. Must be called after show()
((TextView)welcomeAlert.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());

次のように表示されます。

画像1

これは期待どおりに機能し、すべてのクリックはクリック可能です。

今、私は同じことを望んでいますが、カスタムレイアウトを使用しています。

TextViewこのように私のものを作成しましたinfo.xml

<TextView
    android:id="@+id/infoDetailText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/infoVersionTitle"
    android:autoLink="all"
    android:linksClickable="true"
    android:padding="4dp" />

そして、これはコードです:

    Context ctx = this;
    LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.info, (ViewGroup) findViewById(R.id.infoLayout));

    AlertDialog.Builder about = new AlertDialog.Builder(ctx);
    about.setView(layout);
    about.setTitle("Data");
    about.setIcon(R.drawable.info);

    AlertDialog displayInfo = about.create();
    displayInfo.show();
    // Make the textview clickable. Must be called after show()
    TextView textView = (TextView) displayInfo.findViewById(R.id.infoDetailText);
    textView.setText(R.string.link_text_manual);
    textView.setMovementMethod(LinkMovementMethod.getInstance());

上記のコードでは、次のように表示されます (リンクはクリックできず、リンクとしてマークされていません):

画像2

外すと

    textView.setMovementMethod(LinkMovementMethod.getInstance());

以下の画像のように表示されます (リンクはリンクとしてマークされていますが、クリック可能ではありません)。

画像3

Linkifyandも使用しようとしましandroid:autoLink="web"たが、結果は常に同じです。

setMessage()動作しますが、カスタム レイアウトではTextView動作しません。

おそらくこれは簡単ですが、うまくいかないようです。助言がありますか?

ありがとう

4

3 に答える 3

7

android:autoLink="all", android:clickable="true"&なしで TextView を定義しましたandroid:linksClickable="false"

以下のように info.xml TextView の場合

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/infoDetailText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="4dp" />
于 2012-08-22T09:53:31.833 に答える
7

とにかく、あなたのコードは完璧に動作します...

AlertDialog のコード:

LayoutInflater inflater = LayoutInflater.from(ctx);
View layout = inflater.inflate(R.layout.info, null);
AlertDialog.Builder about = new AlertDialog.Builder(ctx);
about.setTitle("Data");
about.setIcon(R.drawable.info);

// Make the textview clickable. Must be called after show()
TextView textView = (TextView) layout.findViewById(R.id.infoDetailText);
textView.setText(R.string.link_text_manual);
textView.setMovementMethod(LinkMovementMethod.getInstance());
about.setView(layout);
AlertDialog displayInfo = about.create();
displayInfo.show();

TextView XML のコード:

<TextView
    android:id="@+id/infoDetailText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/infoVersionTitle"
    android:padding="4dp" />

2つの属性を削除..

android:autoLink="all"
android:linksClickable="true"
于 2012-08-22T10:04:13.600 に答える
0

これを試して

setText(Html.fromHtml(String));
于 2012-08-22T09:17:45.967 に答える