开发者

alertDialog button go to URI

开发者 https://www.devze.com 2023-04-07 00:27 出处:网络
As the title says, I want to make a button in my alertDialog of my app go to a certain URI, and I was wondering how i would do this?

As the title says, I want to make a button in my alertDialog of my app go to a certain URI, and I was wondering how i would do this?

heres and excerpt of the code:

                    // 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();

instead of making display the toast info saying the button is broke, I actually want it to launch the browser and take the user to a URI.

There has to be a way...

Ideas?

Thanks!

Updated with more code..


Start intent in onClick() handler:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号