【问题标题】:alertDialog button go to URIalertDialog 按钮转到 URI
【发布时间】:2011-11-23 02:50:48
【问题描述】:

正如标题所说,我想让我的应用程序的 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 信息。

一定有办法……

想法?

谢谢!

更新了更多代码..

【问题讨论】:

    标签: java android hyperlink android-alertdialog


    【解决方案1】:

    onClick() 处理程序中启动意图:

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

    【讨论】:

      猜你喜欢
      • 2011-08-14
      • 1970-01-01
      • 2015-08-24
      • 2011-04-10
      • 2011-12-14
      • 1970-01-01
      • 2011-08-09
      • 2018-06-21
      • 1970-01-01
      相关资源
      最近更新 更多