[英]Display images through array in Android Studio
I'm trying to re-rig a quiz app to instead of displaying text questions, will display images (Ishihara slides to be specific). 我正在尝试重新装备测验应用程序,而不是显示文本问题,而是显示图像(具体来说是石原幻灯片)。 For reference, here's a screenshot of the original quiz app:
供参考,以下是原始测验应用程序的屏幕截图:
When a user selects the true or false buttons, a toast appears with the result. 当用户选择“是”或“否”按钮时,将显示烤面包和结果。 Straightforward, and the previous/next buttons cycle through the questions.
直截了当,然后上一个/下一个按钮循环浏览问题。 The questions are being stored as such:
问题被这样存储:
final QuestionAndAnswer[] mQandA = new QuestionAndAnswer[]{
/*1*/ new QuestionAndAnswer(R.string.question_northAmerica, true),
/*2*/ new QuestionAndAnswer(R.string.question_antarctica, false),
/*3*/ new QuestionAndAnswer(R.string.question_canada, false),
/*4*/ new QuestionAndAnswer(R.string.question_madagascar, true),
/*5*/ new QuestionAndAnswer(R.string.question_wonders, false)
};
I thought that pointing the new QuestionAndAnswer
at R.drawable.imagename
could accomplish this, but instead just displays the image's location as text. 我认为,将
new QuestionAndAnswer
指向R.drawable.imagename
可以完成此操作,而只是将图像的位置显示为文本。 And changing it to new ImageView(R.drawable.imagename, true)
throws the error: 并将其更改为
new ImageView(R.drawable.imagename, true)
会引发错误:
ImageView (android.content.Context, android.util.AttributeSet)in ImageView cannot be applied to (int,boolean)
ImageView中的ImageView(android.content.Context,android.util.AttributeSet)无法应用于(int,boolean)
I'm sorry, I'm still very new to Android but as you've probably put together by now, I'm a student and don't have a choice but to do this. 抱歉,对于Android来说我还很陌生,但是正如您现在可能已经将它们放在一起一样,我是一名学生,别无选择,只能这样做。
If you have something like this on layout xml 如果布局xml中有类似的内容
<RelativeLayout ...
...
<TextView android:id="@+id/text_view_id" ... />
...
</RelativeLayout>
You need to change it to 您需要将其更改为
<RelativeLayout ...
...
<ImageView android:id="@+id/image_view_id" ... />
...
</RelativeLayout>
Then on your activity class, maybe you have something like below 然后在您的活动课上,也许您有类似下面的内容
TextView textView;
public void onCreate() {
textView = (TextView) findViewById(R.id.text_view_id);
....
textView.setText(mQandA[i].question)
}
Where mQandA[i].question is your question resource aka R.string.question_northAmerica Change it to 其中mQandA [i] .question是您的问题资源,又名R.string.question_northAmerica更改为
ImageView imageView;
public void onCreate() {
imageView = (ImageView) findViewById(R.id.image_view_id);
...
imageView.setImageResource(mQandA[i].question)
}
Where mQandA[i].question is your image resource aka R.drawable.imagename 其中mQandA [i] .question是您的图像资源,即R.drawable.imagename
EDIT 1 编辑1
change every appearance of 改变一切
textView.setText(mQandA[i].question)
with 同
imageView.setImageResource(mQandA[i].question)
counterpart 对方
You would have to display the questions in an ImageView. 您将不得不在ImageView中显示问题。
This means that you can't just point it to a drawable, you have to edit the XML layout files, and change much of the other parts of the program. 这意味着您不能仅仅将其指向可绘制对象,还必须编辑XML布局文件,并更改程序的许多其他部分。
This would include the actual code to display the questions. 这将包括显示问题的实际代码。
You could edit your question and include the actual Java and XML files. 您可以编辑问题并包括实际的Java和XML文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.