java - 重载Android应用程序?

标签 java android methods

我的程序被设计成滑动益智游戏。我目前正在研究随机播放按钮,该按钮将使用随机数将瓷砖移动一定时间,以便玩家可以解决棋盘。

目前,当我按下随机播放按钮时,我遇到了一条错误消息:“无法执行 Activity 的方法”。当它在 while 循环之外时,我可以继续按下按钮,但我必须在每次点击之间留出一定的时间。我在考虑如何使程序重载...但我不确定如何减少负载...

    public void shuffleTiles(View v){ //Shuffles the tiles using random numbers

    int tileToMove;

    while (computerMoves < 5){
        tileToMove = randomNumbers.nextInt(12);
        moveTile(tileToMove, false);
    }

该程序的主要症结在于此方法,该方法交换图像以显示图 block 已移动:

    private void moveTile(int button, boolean playerMove) { //The main method which causes a tile to be moved

    int tileToReplace = movePossibleTest(button); //Run the test to see if there is a blank square next to it
    if (tileToReplace != 0){

        Drawable originalImage = buttons[button-1].getDrawable(); //Saves a drawable of the original image
        Drawable blankImage = buttons[tileToReplace-1].getDrawable(); //Saves a drawable of the blank tile

        buttons[button-1].setImageDrawable(blankImage); //Swaps the images
        buttons[button-1].setTag("blank");

        buttons[tileToReplace-1].setImageDrawable(originalImage); //Swaps the tags that identify which is the blank tag
        buttons[tileToReplace-1].setTag(null);

        if (playerMove){ //If the move was initiated by a player click
            moveCount(true);
        }
        else moveCount(false);
    }
}

最佳答案

如果您有其他 Activity 使您的应用停滞不前,您可以确保使用 activity lifecycle 关闭它们。 .这帮助我解决了一个特定项目中的一些卡住问题。

关于java - 重载Android应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10657567/

相关文章:

java - `notifyDataSetChanged` 我错过了什么?

C++:访问虚拟方法

mysql - 如何在选项卡中传递方法(Ionic 2)

java - 使用java中的方法

java - 如何获取 View 的宽度和高度

android - 为平台 2.1 构建 Android-openssl 库

java - 使用 @autowired 到 DI 后得到一个 null 对象

java - 垃圾收集问题

java - Android 上如何识别用户?

java - 使用 jar 命令更新特定目录中 JAR 中的文件