2011-09-22 76 views
0

正如标题所说,我想在我的应用程序的alertDialog中创建一个按钮,转到某个URI,并且我在想我该怎么做?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。

必须有一种方法...

想法?

谢谢!在onClick()处理

与更多的代码更新..

回答

1

开始意图:

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

,完美的工作!非常感谢! – death2all110