I am making an app for android. I am trying to guess what song the user just played on xylophone. I have: private List<String> mDespacito = new ArrayList<String>(Arrays.asList("f", "a","d","d"));
and private List<String> mPlayed = new ArrayList<String>();
When user presses one key on the xylophone, I add the key he pressed to the mPlayed arraylist, like this:
public void playD(View v){
Log.d("Xylophone", "Played D!");
mSoundPool.play(mDSoundId,LEFT_VOLUME,RIGHT_VOLUME,PRIORITY,NO_LOOP,NORMAL_PLAY_RATE);
mPlayed.add("d");
CheckForSong();
}
Now, CheckForSong contains:
public void CheckForSong(){
if (mPlayed.containsAll(mDespacito)){
Log.d("Xylophone","You just played despacito");
mPlayed.removeAll(mDespacito);
}
}
So, it should do:
played F
played A
played D
played D
You just played despacito
But it does:
played F
played A
played D
You just played despacito
played D
And you can do even:
played F
played G
played A
played G
played D
You just played despacito
And I know why: Because of if (mPlayed.containsAll(mDespacito))
just checks if elements of mDespacito are in mPlayed. But i need to check if there are all elements of mDespacito (Including those which are there twice) and if they are in the right order. Is there any command like that I can use? Thanks