admin管理员组

文章数量:1434949

How to run an action in a loop in Android . I tried this code but it is not what i need, I need to call a function in which with help of TTS a word must be spoken and then loop to the next word until to the end of string array. my code:

        playButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(minusButton.isEnabled()){
                minusButton.setEnabled(false);
            }

            if(plusButton.isEnabled()){
                plusButton.setEnabled(false);
            }

            new Thread() {
                @Override
                public void run() {

                    do {
                            speakText();

                    }
                    while (i <= myTextCharater.length);

                }
            }.start();
        }
    });

Function code:

    private void speakText(){
    String str = myTextCharater[i];
    tts.setSpeechRate(Float.parseFloat(speedSpeakFinal + "f"));
    tts.speak(str, TextToSpeech.QUEUE_ADD, null, null);

    i++;

}

The problem is that it loops to the end end only last word is pronounced.

Each spoken word must change its color during pronouncing and back.

本文标签: Independent action in loop AndroidStack Overflow