Android:图像作为数组中的答案

时间:2014-04-23 12:48:02

标签: android eclipse image imageview

我正在尝试添加图像作为对阵列的响应,但我不知道该怎么做。我对此非常陌生,所以请耐心等待(使用Eclipse)。

public String[] mAnswers = {

"Do you really have to ask me about that? It's a yes.",
"Concentrate and ask again",
"You have no life. So yes.",
"It's okay to play.",
-image here that I wish to add-

};

我将图像保存在res \ drawable-mdpi \ gaben.png

任何帮助将不胜感激!

3 个答案:

答案 0 :(得分:1)

对于这种情况,您可以使用两个数组

一个是字符串数组,另一个是int数组。看这个

public String[] mAnswers = {
"Do you really have to ask me about that? It's a yes.",
"Concentrate and ask again",
"You have no life. So yes.",
"It's okay to play."
};

public String[] images = {
R.drawable.image1,
R.drawable.image2,
R.drawable.image3,
R.drawable.image4
};

现在您可以根据需要使用这两个数组

答案 1 :(得分:0)

案例1:图像为位图

mAnswers变量声明为String [],因此是一个字符串数组。

字符串不是图像。

您无法混合对象类型。

您的图像需要存储在其他位置,或者您需要以不同方式键入mAnswers,例如Object []。

案例2:图像为路径

将位图的路径作为String保存到数组中。

答案 2 :(得分:0)

创建一个包装信息并声明此对象数组的对象

public class Bean {
  public final int mImageId;
  public final String mMessage;
  public Bean(int imageId, String message) {
    mImageId = imageId;
    mMessage = message;
  }
}

   Bean[] info = { new Bean(R.drawable.image1, "my first message"), ... } ;