【发布时间】:2016-08-03 00:39:25
【问题描述】:
我的可绘制对象中有 100 多张图片。它基本上是一个类别。我正在从包含类别的列的服务器调用数据。我的图像被命名为 cat_image1、cat_image2、cat_image3 等。服务器发送相应的 srting 分别为 Image1、Image2、Image3 等。我认为这不是我正在做的事情
String catString = someJSONObject.getString(Config.POI_CATEGORY);
if (catString == "image1") {
someView.setImage(getResources().getDrawable(R.mipmap.image1));
}
else if (catString == "image2") {
someView.setImage(getResources().getDrawable(R.mipmap.image2));
}
else if (catString == "image3") {
someView.setImage(getResources().getDrawable(R.mipmap.image3));
}
...
...
...
【问题讨论】:
-
你不能像那样比较字符串,用这个改变 if(catString.equals("image1")) { // 做你的事情 }
-
我认为您应该将这 100 张图像存储在您的服务器上并返回这些图像的 url,然后相应地设置该图像