Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.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
Android 如何将短语拆分为单词,并在每个单词中显示相应的图像?_Android_Android Studio - Fatal编程技术网

Android 如何将短语拆分为单词,并在每个单词中显示相应的图像?

Android 如何将短语拆分为单词,并在每个单词中显示相应的图像?,android,android-studio,Android,Android Studio,我已经在下面尝试了这些代码,但它只读取单词而不是短语,这些代码有效,不符合我的要求。用户输入的每个单词只会添加并添加到空数组列表中。我想要实现的是,当用户输入一个短语时,它将按空格分割并存储在一个空数组列表中。当条件为真时,该数组列表将与另一个包含单词的数组列表进行比较,它将显示相应的图像,现在将读取短语中的下一个单词 private List<String> wordsList; private ArrayList<String>wordsToDisplay=new

我已经在下面尝试了这些代码,但它只读取单词而不是短语,这些代码有效,不符合我的要求。用户输入的每个单词只会添加并添加到空数组列表中。我想要实现的是,当用户输入一个短语时,它将按空格分割并存储在一个空数组列表中。当条件为真时,该数组列表将与另一个包含单词的数组列表进行比较,它将显示相应的图像,现在将读取短语中的下一个单词

 private List<String> wordsList;
private ArrayList<String>wordsToDisplay=new ArrayList<>();
boolean missingGIF;
int counter;
}

这是我的动画监听器,它用用户输入的所有单词显示相应的图像

@Override
public void onAnimationCompleted(int loopNumber) {

    if(wordsToDisplay.size()>1){

        if(counter<wordsToDisplay.size()){


            try{

                counter++;

                gifImageView.setImageResource(getResources().getIdentifier(wordsToDisplay.get(counter),"drawable",getPackageName()));
                animation = (GifDrawable)gifImageView.getDrawable();
                resetAnimation();
                startAnimation();
                animation.addAnimationListener(this);




            }
            catch(IndexOutOfBoundsException e){
                Log.d("Expected",e.toString());
            }


        }
    }

}
移除计数器并使用下面的逻辑

@Override
public void onAnimationCompleted(int loopNumber) {

    if(!wordsToDisplay.isEmpty()){
        String nextWord = wordsToDisplay.remove(0);
        gifImageView.setImageResource(getResources().getIdentifier(nextWord,"drawable",getPackageName()));
        animation = (GifDrawable)gifImageView.getDrawable();
        resetAnimation();
        startAnimation();
        animation.addAnimationListener(this); 
    }
}
@Override
public void onAnimationCompleted(int loopNumber) {

    if(wordsToDisplay.size()>1){

        if(counter<wordsToDisplay.size()){


            try{

                counter++;

                gifImageView.setImageResource(getResources().getIdentifier(wordsToDisplay.get(counter),"drawable",getPackageName()));
                animation = (GifDrawable)gifImageView.getDrawable();
                resetAnimation();
                startAnimation();
                animation.addAnimationListener(this);




            }
            catch(IndexOutOfBoundsException e){
                Log.d("Expected",e.toString());
            }


        }
    }

}
@Override
public void onAnimationCompleted(int loopNumber) {

    if(!wordsToDisplay.isEmpty()){
        String nextWord = wordsToDisplay.remove(0);
        gifImageView.setImageResource(getResources().getIdentifier(nextWord,"drawable",getPackageName()));
        animation = (GifDrawable)gifImageView.getDrawable();
        resetAnimation();
        startAnimation();
        animation.addAnimationListener(this); 
    }
}