Android Studio - startActivity

时间:2015-06-14 23:52:43

标签: android android-studio

的getch();命令在c ++中用于暂停程序,我应该在Android Studio中使用什么来暂停程序?

  for (int i = 0; i < 2; i++){
        if ((b[0].getText().toString()  == c && b[1].getText().toString()  == c && b[2].getText().toString()  == c) || (b[3].getText().toString()  == c && b[4].getText().toString()  == c && b[5].getText().toString()  == c) || (b[6].getText().toString()  == c && b[7].getText().toString()  == c && b[8].getText().toString()  == c) || (b[0].getText().toString()  == c && b[3].getText().toString()  == c && b[6].getText().toString()  == c) || (b[1].getText().toString()  == c && b[4].getText().toString()  == c && b[7].getText().toString()  == c) || (b[2].getText().toString()  == c && b[5].getText().toString()  == c && b[8].getText().toString()  == c) || (b[0].getText().toString()  == c && b[4].getText().toString()  == c && b[8].getText().toString()  == c) || (b[2].getText().toString()  == c && b[4].getText().toString()  == c && b[6].getText().toString()  == c)){
            if (c == "X"){
                paper.setText("You Won the Game.");


            }
            else{
                paper.setText("Computer Won the Game.");
            }
        }

我想暂停使用paper.setText()显示游戏结果的程序;命令。

1 个答案:

答案 0 :(得分:1)

如果您在活动内,只需致电this.finish();

编辑:我不确定你想要做什么,但是在没有用户同意的情况下关闭程序通常不是好的做法。显示文本后,最好显示如下对话框: “你想再玩一次吗?”  [是] [关闭游戏]

您可以使用以下代码完成此操作:

new AlertDialog.Builder(this)
    .setTitle("Play again?")
    .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
            // start game over
        }
     })
    .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
            MyActivity.this.finish(); 
//use the class name of you activity + this 
//to access your Activity's finish rather than try and perform finish on an onClick
        }
     })
    .setIcon(android.R.drawable.myicon)
     .show();