1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| public View getView(int position, View convertView, ViewGroup parent) {
final ImageView i = new ImageView(this.myContext);
String url[] =new String[]{"http://www.anddev.org/images/tiny_tutheaders/weather_forecast.png","http://www.anddev.org/images/tiny_tutheaders/cellidtogeo.png"};
new AsyncTask<String, Void, Bitmap>() {
private Bitmap bm;
@Override
protected Bitmap doInBackground(String... urls) {
/* Open a new URL and get the InputStream to load data from it. */
URL aURL;
try {
aURL = new URL(urls[0]);
Log.i("URL", urls[0]);
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
/* Buffered is always good for a performance plus. */
BufferedInputStream bis = new BufferedInputStream(is);
/* Decode url-data to a bitmap. */
bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bm;
}
@Override
protected void onPostExecute(Bitmap result) {
if (result != null) {
Log.i("result", ""+result);
i.setImageBitmap(result);
}
}
}.execute(url);
return i;
} |
Partager