【发布时间】:2019-03-20 07:33:25
【问题描述】:
我正在练习开发应用,但遇到了问题。我想从数组中删除两个元素,但android studio只能删除一个,如果我再添加一个,应用程序将崩溃,下面是我的代码,现在我只输入一个代码来删除第一个元素,否则我需要删除最后一个元素答案的选择将混合数组。
ArrayList<ArrayList<String>> quizArray = new ArrayList<>();
String quizData[][] = {
{"quadrilateral","quadrilateral","triangle","heptagon","pentagon","hexagon","decagon","Which one is the green polygon just now ?"},
{"triangle","triangle","heptagon","quadrilateral","pentagon","octagon","decagon","Which one is the red polygon just now ?"},
{"circle","circle","triangle","quadrilateral","pentagon","nonagon","decagon","Which one is the black polygon just now ?"},
{"star","star","circle","octagon","pentagon","hexagon","decagon","Which one is the brown polygon just now ?"},
{"decagon","decagon","triangle","circle","pentagon","hexagon","star","Which one is the pink polygon just now ?"},
{"heptagon","heptagon","decagon","quadrilateral","pentagon","hexagon","star","Which one is the yellow polygon just now ?"},
{"hexagon","hexagon","decagon","heptagon","pentagon","octagon","star","Which one is the sky blue polygon just now ?"},
{"nonagon","nonagon","circle","quadrilateral","triangle","hexagon","star","Which one is the orange polygon just now ?"},
{"pentagon","pentagon","nonagon","octagon","heptagon","hexagon","circle","Which one is the purple polygon just now ?"},
{"octagon","octagon","triangle","quadrilateral","pentagon","hexagon","star","Which one is the dark blue polygon just now ?"}
};
public void Show_Next_Quiz(){
Random random = new Random();
int Random_Num = random.nextInt(quizArray.size());
ArrayList<String> quiz = quizArray.get(Random_Num);
Question1.setText(quiz.get(7));
iV1.setImageResource(
getResources().getIdentifier(quiz.get(0), "drawable", getPackageName())
);
iV2.setImageResource(
getResources().getIdentifier(quiz.get(0), "drawable", getPackageName())
);
iV3.setImageResource(
getResources().getIdentifier(quiz.get(0), "drawable", getPackageName())
);
iV4.setImageResource(
getResources().getIdentifier(quiz.get(0), "drawable", getPackageName())
);
iV5.setImageResource(
getResources().getIdentifier(quiz.get(0), "drawable", getPackageName())
);
iV6.setImageResource(
getResources().getIdentifier(quiz.get(0), "drawable", getPackageName())
);
Right_Answer = quiz.get(1);
quiz.remove(0);
//quiz.remove(7);
Collections.shuffle(quiz);
ans1.setText(quiz.get(1));
ans2.setText(quiz.get(2));
ans3.setText(quiz.get(3));
ans4.setText(quiz.get(4));
ans5.setText(quiz.get(5));
ans6.setText(quiz.get(6));
quizArray.remove(Random_Num);
}
【问题讨论】:
-
Android Studio 无法编码。所以没有 :P 查看
remove()的文档以获取 Java 中的ArrayList。你会知道从那里做什么。 docs.oracle.com/javase/7/docs/api/java/util/… -
哦,我会花点时间弄清楚,谢谢=)
标签: java android arrays arraylist