android - 如何在 cocos2d for android 中显示带有确认消息和是/否按钮的 UIAlertView?

标签 android c++ cocos2d-x

在 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/

相关文章:

Android Studio 获取 "Must implement OnFragmentInteractionListener"

Android Activity 开关暂时失去全屏

c++ - 返回 vector 的第一个元素被(重新)设置为 0

C++ 作业函数错误

C++ - 如何反向播放动画 Cocos2DX

android - 在 cocos2d-x 中有没有更好的方法来获取系统时间?

android - 在结束cocos2dx之后重复背景音乐吗?

android - 如何缩短拒绝连接的时间?

java - 我如何使用 android 的 getResources

c++ - 字符串结束字符是否损坏内存?缓冲区[大小] ='\0' ;