所以我想用android studio做一个简单的测验。然后我已经进行了测验,效果很好。我的测验使用文本作为问题和答案。而不是使用文本,我也想制作图像作为问题和答案。有什么建议吗? (对不起,我是编程的新手,这也是我的第一学期)
这是我之前测验的代码(文字为问题和答案) 问题库代码:
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2 0762a183aaa3
这是测验活动代码的代码:
public class QuestionBank {
private String textQuestions [] = {
"1. What is the most populated country in the world ?",
"2. Who is the first president of USA ?",
"3. What animal that can fly ?",
"4. 1000 + 945 = ?",
"5. What year now ?"
};
// array of multiple choices for each question
private String multipleChoice [][] = {
{"Russia", "China", "USA", "Brazil"},
{"Obama", "Vladimir Putin", "George Washington", "Donald Trump"},
{"Fish", "Cat", "Bird", "Snake"},
{"1999", "2018", "1945", "2000"},
{"1999", "2000", "2010", "2018"}
};
private String mCorrectAnswers[] = {"China", "George Washington", "Bird",
"1945", "2018"};
public int getLength(){
return textQuestions.length;
}
public String getQuestion(int a) {
String question = textQuestions[a];
return question;
}
public String getChoice(int index, int num) {
String choice0 = multipleChoice[index][num-1];
return choice0;
}
public String getCorrectAnswer(int a) {
String answer = mCorrectAnswers[a];
return answer;
}
}
答案 0 :(得分:0)
写一个数组来存储来自可绘制文件夹的图像,而不是字符串数组
private Integer[] mThumbIds = {
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7
};
然后在xml中而不是TextView中使用ImageView,然后在按钮中使用ImageButton。之后,您可以将ImageView和ImageButton设置为
imageview= (ImageView)findViewById(R.id.imageView);
imageview.setImageDrawable(getResources().getDrawable(mThumbIds[1]));