从消息AlertDialog创建新活动

时间:2013-02-01 17:32:38

标签: android android-activity android-alertdialog

我想点击AlertDialog显示的部分文本并开始一项新活动。 我只是不知道是否有可能。 这是我的代码示例

case R.id.about:
        final AlertDialog d = new AlertDialog.Builder(this)
        .setPositiveButton(android.R.string.ok, null)
        .setMessage(Html.fromHtml(getResources().getString(R.string.infoAuthor)+" <br> <a href=\"https://www.youtube.com">click here for help</a>"))
        .create();
        d.show();
        // Make the textview clickable. Must be called after show()   
        ((TextView)d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());

1 个答案:

答案 0 :(得分:0)

不是直接设置AlertDialog的消息,而是创建TextView并在其上设置HTML和LinkMovementMethod。然后使用此TextView调用AlertDialog.Builder#setView()。使用代码的示例:

case R.id.about:
        TextView tv = new TextView(this);
        tv.setText(Html.fromHtml(getResources().getString(R.string.infoAuthor)+" <br> <a href=\"https://www.youtube.com">click here for help</a>");
        tv.setMovementMethod(LinkMovementMethod.getInstance());

        final AlertDialog d = new AlertDialog.Builder(this)
        .setPositiveButton(android.R.string.ok, null)
        .setView(tv);
        .create();
        d.show(getFragmentManager, "tag");