以前の質問に続いて、カスタムでハイパーリンクを管理する際にまだ問題があります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 <a> 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());
次のように表示されます。
これは期待どおりに機能し、すべてのクリックはクリック可能です。
今、私は同じことを望んでいますが、カスタムレイアウトを使用しています。
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());
上記のコードでは、次のように表示されます (リンクはクリックできず、リンクとしてマークされていません):
外すと
textView.setMovementMethod(LinkMovementMethod.getInstance());
以下の画像のように表示されます (リンクはリンクとしてマークされていますが、クリック可能ではありません)。
Linkify
andも使用しようとしましandroid:autoLink="web"
たが、結果は常に同じです。
setMessage()
動作しますが、カスタム レイアウトではTextView
動作しません。
おそらくこれは簡単ですが、うまくいかないようです。助言がありますか?
ありがとう