2017-07-19 20 views
-2

如何给Alert框添加一个函数意味着我在andriod中创建了一个Tic Tac Toe游戏问题是当一个玩家赢得游戏时,一个Alert框出现并询问“想再次玩”如果他点击是,那么游戏再次播放,但在警报框中,我没有再次运行功能在Android中需要关于Alert Box的帮助

回答

0

此代码将解决您的问题。

AlertDialog.Builder builder = new AlertDialog.Builder(this); 
     builder.setMessage("Unable to Access Camera, Face Unlock will not work!") 
       .setCancelable(false) 
       .setPositiveButton("OK", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int id) { 

         **//write your code here in case of OK** 
        } 
       }) 
       .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int id) { 

         **//write your code here in case of user press cancel** 
        } 
       }); 
     AlertDialog alert = builder.create(); 
     alert.show(); 
+1

在发布之前,请花些时间至少格式化您的代码。 – csmckelvey