在Android的AlertDialog中超链接电话号码

Ava*_*i Y 4 java android hyperlink android-alertdialog

我有一个AlertDialog,其中包含"有关更多信息,请致电1-800-200-1000"的文字.

这是我单击ListView项目时警报对话框显示的代码:

 final AlertDialog.Builder builder = new AlertDialog.Builder(this);
        final SpannableString s = new SpannableString("1-800-200-1000");
        Linkify.addLinks(s, Linkify.ALL);
        ListView.setOnItemClickListener(new OnItemClickListener(){

        public void onItemClick(AdapterView<?> parent, View view,
              int position, long id) {

          builder.setMessage("For more information, Please Call "+s)
           .setCancelable(true)
           .setPositiveButton("OK", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                 dialog.dismiss();
               }
           });
          AlertDialog alert = builder.create();
          alert.show();
        }});
Run Code Online (Sandbox Code Playgroud)

在这里,我希望超链接"1-800-200-1000",并在点击此时,应实现另一个呼叫功能对话框.

这是我的CallDialog for Call Function:

    final Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Do you want to Call?");
    builder.setCancelable(false);
    builder.setPositiveButton("Call", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
       Intent dial = new Intent();
            dial.setAction("android.intent.action.DIAL");dial.setData(Uri.parse("tel:"+ Phone));
                                        startActivity(dial); 

                                    }
                                });
                                builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                       // Toast.makeText(getApplicationContext(),"Activity will continue",Toast.LENGTH_LONG).show();
                                        dialog.cancel();
                                    }
                                });
                                AlertDialog dialog = builder.create();
                                dialog.show();
Run Code Online (Sandbox Code Playgroud)

请帮我解决两个问题:

1.如何在第一个对话框中超链接电话号码?

2.单击超链接电话号码时如何嵌入Call AlertDialog?

提前致谢.

Tof*_*mad 5

试试这个:

Spannable spans = (Spannable) text;
ClickableSpan clickSpan = new ClickableSpan() {
@Override
public void onClick(View widget) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://"+ url));
}
public void updateDrawState(TextPaint ds) {
    //override link-centric text appearance
}
};
int index = (text.toString()).indexOf(url);
spans.setSpan(clickSpan, index, url.length() + index,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Run Code Online (Sandbox Code Playgroud)