使用 DialogFragment 的 Web 链接 [重复]
Posted
技术标签:
【中文标题】使用 DialogFragment 的 Web 链接 [重复]【英文标题】:Web Link using DialogFragment [duplicate] 【发布时间】:2015-01-09 19:42:04 【问题描述】:我有这个对话框片段,但我正在尝试获取它,以便当用户单击“我的其他应用程序”按钮时,他们会被重定向到一个网址。有没有办法做到这一点。 任何帮助表示赞赏 谢谢
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
// TODO Auto-generated method stub
AlertDialog.Builder theDialog = new AlertDialog.Builder(getActivity());
theDialog.setTitle("About");
String d1 = "Thanks For Downloading! ";
String d2 = "Made by ME";
theDialog.setMessage(d1 +"\n"+ d2 );
theDialog.setPositiveButton("My Other Apps", new DialogInterface.OnClickListener()
@Override
public void onClick(DialogInterface dialog, int which)
Toast.makeText(getActivity(), "Clicked My Other Apps",
Toast.LENGTH_SHORT).show();
);
theDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
@Override
public void onClick(DialogInterface dialog, int which)
Toast.makeText(getActivity(), "Clicked Cancel",
Toast.LENGTH_SHORT).show();
);
return theDialog.create();
【问题讨论】:
发帖前请稍作研究 @njzk2 对不起,谢谢! 【参考方案1】:@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
// TODO Auto-generated method stub
AlertDialog.Builder theDialog = new AlertDialog.Builder(getActivity());
theDialog.setTitle("About");
String d1 = "Thanks For Downloading! ";
String d2 = "Made by ME";
theDialog.setMessage(d1 +"\n"+ d2 );
theDialog.setPositiveButton("My Other Apps", new DialogInterface.OnClickListener()
@Override
public void onClick(DialogInterface dialog, int which)
String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
);
theDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
@Override
public void onClick(DialogInterface dialog, int which)
Toast.makeText(getActivity(), "Clicked Cancel",
Toast.LENGTH_SHORT).show();
);
return theDialog.create();
【讨论】:
【参考方案2】:在您的按钮点击时执行此操作:
@Override
public void onClick(DialogInterface dialog, int which)
String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
【讨论】:
以上是关于使用 DialogFragment 的 Web 链接 [重复]的主要内容,如果未能解决你的问题,请参考以下文章