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);
精彩评论