のは、この
URLのimg_value =新しいURL(IMG [位置])のようにしてみましょう。
Bitmap mIcon1 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
holder.image.setImageBitmap(mIcon1);
は、ここでは画像表示のためのあなたのxmlに保存画像ウィジェットholder.imageです。
指定されたURLから画像をロードします。 またはDrawableManagerという名前のクラスを作成して、以下のようにしてください。
新しいDrawableManager()。fetchDrawableOnThread(VAL3 [position]、holder.icon);
package com.fsp.demo;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.SoftReference;
import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Map;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.ImageView;
public class DrawableManager {
@SuppressWarnings("unchecked")
private final Map drawableMap;
public DrawableManager() {
drawableMap = new HashMap<String, SoftReference<Drawable>>();
}
@SuppressWarnings("unchecked")
public Drawable fetchDrawable(String urlString) {
SoftReference<Drawable> drawableRef = (SoftReference<Drawable>) drawableMap
.get(urlString);
if (drawableRef != null) {
Drawable drawable = drawableRef.get();
if (drawable != null)
return drawable;
// Reference has expired so remove the key from drawableMap
drawableMap.remove(urlString);
}
if (Constants.LOGGING)
Log.d(this.getClass().getSimpleName(), "image url:" + urlString);
try {
InputStream is = fetch(urlString);
Drawable drawable = Drawable.createFromStream(is, "src");
drawableRef = new SoftReference<Drawable>(drawable);
drawableMap.put(urlString, drawableRef);
if (Constants.LOGGING)
Log.d(this.getClass().getSimpleName(),
"got a thumbnail drawable: " + drawable.getBounds()
+ ", " + drawable.getIntrinsicHeight() + ","
+ drawable.getIntrinsicWidth() + ", "
+ drawable.getMinimumHeight() + ","
+ drawable.getMinimumWidth());
return drawableRef.get();
} catch (MalformedURLException e) {
if (Constants.LOGGING)
Log.e(this.getClass().getSimpleName(), "fetchDrawable failed",
e);
return null;
} catch (IOException e) {
if (Constants.LOGGING)
Log.e(this.getClass().getSimpleName(), "fetchDrawable failed",
e);
return null;
}
}
@SuppressWarnings("unchecked")
public void fetchDrawableOnThread(final String urlString,
final ImageView imageView) {
// Log.v("Drawable_url",urlString);
SoftReference<Drawable> drawableRef = (SoftReference<Drawable>) drawableMap
.get(urlString);
if (drawableRef != null) {
Drawable drawable = drawableRef.get();
if (drawable != null) {
imageView.setImageDrawable(drawableRef.get());
return;
}
// Reference has expired so remove the key from drawableMap
drawableMap.remove(urlString);
}
final Handler handler = new Handler() {
public void handleMessage(Message message) {
imageView.setImageDrawable((Drawable) message.obj);
}
};
Thread thread = new Thread() {
@Override
public void run() {
// TODO : set imageView to a "pending" image
Drawable drawable = fetchDrawable(urlString);
Message message = handler.obtainMessage(1, drawable);
handler.sendMessage(message);
}
};
thread.start();
}
private InputStream fetch(String urlString) throws MalformedURLException,
IOException {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet request = new HttpGet(urlString);
HttpResponse response = httpClient.execute(request);
return response.getEntity().getContent();
}
}
http://stackoverflow.com/questions/4536890/layout-styles-in-android/4536919#4536919 – sahhhm
の再投稿あなたは....私は、アプリケーション全体を書いていないよたものたちを表示します君は。 – st0le