Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 重载android应用程序?_Java_Android_Methods - Fatal编程技术网

Java 重载android应用程序?

Java 重载android应用程序?,java,android,methods,Java,Android,Methods,我的程序被设计成一个滑动益智游戏。我目前正在研究洗牌按钮,该按钮将使用随机数移动瓷砖一段时间,以便棋盘可以由玩家解决 目前,当我按下洗牌按钮时,出现了一条错误消息:“无法执行活动的方法”。当它在while循环之外时,我可以一直按下按钮,但每次单击之间必须留出一定的时间。我在想我是如何让程序过载的。。。但我不知道如何减少负荷 public void shuffleTiles(View v){ //Shuffles the tiles using random numbers in

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

目前,当我按下洗牌按钮时,出现了一条错误消息:“无法执行活动的方法”。当它在while循环之外时,我可以一直按下按钮,但每次单击之间必须留出一定的时间。我在想我是如何让程序过载的。。。但我不知道如何减少负荷

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

    int tileToMove;

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

如果您有其他活动使应用程序陷入困境,您可以确保使用关闭它们。这帮助我解决了一个特定项目中的一些冻结问题

如果您有其他活动阻碍了您的应用程序,您可以确保使用关闭它们。这帮助我解决了一个特定项目中的一些冻结问题

我认为您不应该在ui线程中使用while循环,因为它确实占用大量内存。事实上,我不明白你为什么要首先使用while循环。我用它来洗牌,但现在我想,我可能会在不改变任何ui的情况下运行它,然后将所有的牌交换到它们的计算位置,这会让它超负荷吗?什么是操纵computerMoves?computerMoves是一个计数记录,记录了在我实现“解决”按钮时自动生成的所有动作,我认为你不应该在ui线程中使用while循环——它真的占用大量内存。事实上,我不明白你为什么要首先使用while循环。我用它来洗牌,但现在我想,我可能会在不改变任何ui的情况下运行它,然后将所有的牌交换到它们的计算位置,这会让它超负荷吗?什么是操纵computerMoves?computerMoves是一个计数记录,用于在我执行“解决”按钮时自动生成的所有移动,无需人工交互
    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);
    }
}