整数配列でR.drawable.imgを取るときと同じように、整数配列で画像を撮りたい。サーバから画像を取得し、Androidでint配列に設定する
例えば:int[] images = {R.drawable.a , R.drawable.b , R.drawable.c , R.drawable.d};
サーバーから画像を撮るとき、私はこのように同じ欲しいです。アレイの
宣言:
String images[] = new String[1000];
は、サーバからイメージを取得し、起きていない配列をintにそれを設定します。
public void onResponse(String response) {
Log.d("TAG", "Message Response: " + response.toString());
hideDialog();
try {
JSONObject jsonObj = new JSONObject(response);
boolean error = false;
p = jsonObj.getJSONArray("response");
for (int i = 0 ; i < p.length(); i++) {
JSONObject c = p.getJSONObject(i);
String profilepicture = c.getString("profile_picture");
byte[] decodedString = Base64.decode(profilepicture, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
Drawable drawable = new BitmapDrawable(getResources(),decodedByte);
images[i] = drawable;
}
描画可能な値は[email protected]
です。しかし、整数配列は設定されません。
ImageViewでdrawableを表示することを究極の目標とする場合は、PiccasoまたはAndroid-Universal-Image-Loaderを使用してください。 urlの配列を作成し、このライブラリにurlを渡すと、このライブラリは画像のダウンロードと表示の部分を処理します。また、イメージキャッシュを提供します。 –