我有一个随机消息数组,但我希望它不会选择一个已经被选择的消息,然后在所有消息被选择后重置。
public void showRandomMsg(){
shuffleMsg();
answer1.setText((messageArray[0].getmAns()));
message2.setText((messageArray[0].getmMsg()));
toyView1.setImageResource(messageArray[0].getmImage());
}
Messages m01 = new Messages(R.drawable.crown1, "Mesage 0 A","Message 0 B");
Messages m02 = new Messages(R.drawable.crown2,"Mesage 1 A","Message 1 B");
Messages m03 = new Messages(R.drawable.crown3,"Mesage 2 A","Message 2 B");
Messages m04 = new Messages(R.drawable.crown4,"Mesage 3 A","Message 3 B");
Messages m05 = new Messages(R.drawable.crown5,"Mesage 4 A","Message 4 B");
Messages [] messageArray=new Messages[]{
m01, m02, m03, m04, m05
};
public void shuffleMsg(){
Collections.shuffle(Arrays.asList(messageArray));
}
1条答案
按热度按时间fslejnso1#
您可以为删除一条消息的消息获取程序编写逻辑,如果没有可用的消息,则重新填充: