正如标题所说,我想在我的应用程序的警报对话框中创建一个按钮,转到某个 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/