在 cocos2d iOS 中,我做了类似的事情,它在 iOS 上运行良好。
-(void)showConfirmAlert
{
UIAlertView *alert = [[UIAlertView alloc] init];
[alert setTitle:@"Confirm"];
[alert setMessage:@"Do you pick Yes or No?"];
[alert setDelegate:self];
[alert addButtonWithTitle:@"Yes"];
[alert addButtonWithTitle:@"No"];
[alert show];
[alert release];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
yes
}
else if (buttonIndex == 1)
{
no
}
}
如何在 cocos2d-android (C++) 中使用相同的 UIAlertView
?
最佳答案
你应该尝试:
private void showDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Do you pick Yes or No?");
DialogInterface.OnClickListener positiveEventAction = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Yes action here
}
};
DialogInterface.OnClickListener negativeEventAction = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// No action here
}
};
builder.setPositiveButton("YES", positiveEventAction);
builder.setNegativeButton("NO", negativeEventAction);
AlertDialog dialog = builder.create();
dialog.setTitle("Confirm");
int icon = R.drawable.icon; // Optional
dialog.setIcon(icon);
dialog.show();
}
关于android - 如何在 cocos2d for android 中显示带有确认消息和是/否按钮的 UIAlertView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20218955/