なぜこれがうまくいかないのか、誰にも分かりますか?のstartActivity(i);
動作しない
public class UiHelper {
/**
* About Dialog
*/
public static void showAboutDialog(Activity activity) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(R.string.about_title);
// build view from layout
LayoutInflater factory = LayoutInflater.from(activity);
final View dialogView = factory.inflate(R.layout.about_dialog, null);
TextView versionText = (TextView) dialogView.findViewById(R.id.about_version);
versionText.setText(activity.getString(R.string.about_version) + " " + getVersion(activity));
builder.setView(dialogView);
builder.setIcon(android.R.drawable.ic_dialog_info);
/** builder.setNeutralButton(activity.getString(R.string.button_close),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});**/
builder.setPositiveButton("Facebook",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
String url = "http://www.facebook.com/page/";
final Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i); /** <<-- Error <<--**/
}
});
builder.setNegativeButton("Website",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
String url = "http://www.website.com/";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});
AlertDialog question = builder.create();
question.show();
}
しかし、私はこれがうまくいくことを試みます
働く
AlertDialog.Builder alert = new AlertDialog.Builder(PTRmainActivity.this);
alert.setTitle("About");
alert.setMessage("Version 1.0.0");
alert.setIcon(R.drawable.icon);
alert.setPositiveButton("Facebook",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
String url = "http://www.facebook.com/page/";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});
alert.setNegativeButton("Website",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
String url = "http://www.website.com/";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});
alert.show();