java - 警报对话框按钮转到 URI

标签 java android hyperlink android-alertdialog

正如标题所说,我想在我的应用程序的警报对话框中创建一个按钮,转到某个 URI,我想知道如何做到这一点?

代码摘录如下:

                    // Add a neutral button to the alert box AND assign a listener for said button...
                alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener(){

                    // click listener for box
                    public void onClick(DialogInterface arg0, int arg1){
                        // Button was clicked!!
                        Toast.makeText(getApplicationContext(), "Dialog closed successfully!", Toast.LENGTH_LONG).show();
                    }
                });

                // Add a Forums button to take user to forums...
                alertbox.setPositiveButton("Forums", new DialogInterface.OnClickListener(){

                    //listener for button
                    public void onClick(DialogInterface arg0, int arg1){
                        // Button Pressed!
                        Toast.makeText(getApplicationContext(), "Oops...this button is broke!", Toast.LENGTH_LONG).show();
                    }
                });
                // show it!!!
                alertbox.show();

我实际上希望它启动浏览器并将用户带到一个 URI,而不是显示 toast 信息说按钮已损坏。

一定有办法...

想法?

谢谢!

更新了更多代码..

最佳答案

onClick() 处理程序中启动 Intent :

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse("http://website.com"));
startActivity(intent);

关于java - 警报对话框按钮转到 URI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7520047/

相关文章:

html - 需要帮助修复链接的可点击区域

javascript - 如何在 javascript 中 5 秒后转到链接

html - 根据URL参数动态改变页面内容?

java - 我想打印除最后一个以外的所有字母,然后是最后两个,然后是最后 3 个

java - Android从文件路径获取图像到位图

Android 模拟器在一段时间后失去互联网连接(不活动或 Activity )

android - 我必须如何设置可以在 Android OpenGL-ES 2.0 fragment 着色器中使用它们的纹理?

java - 抽屉导航中 webview 的 findViewById 问题

java - 如何将字符串添加到字符串池中

java - 使用 Java TableRowSorter 对长整型进行排序