Hello at all, i'm developing on Android since the last month and I've
encountered this problem in these days.

If I download an image from Internet with this code isn't correctly viewed:

package org.ti.weather;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;

public class Weather extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);
        ImageView img = (ImageView) findViewById(R.id.weatherimg);

        // this don't function
        try {
            URL aURL = new URL("
http://vdt.meteo.alice.it/meteo/imgs/icone/small/previsioni/notte/sereno.png
");
            URLConnection conn = aURL.openConnection();
            conn.connect();
            InputStream is = conn.getInputStream();
            BufferedInputStream bis = new BufferedInputStream(is);
            Bitmap bm = BitmapFactory.decodeStream(bis);
            bis.close();
            is.close();
            img.setImageBitmap(bm);
        } catch (IOException e) {
            // Reset to 'Dunno' on any error
            showAlert("Error", 0, "Can't download image", "Ok", false);
        }

    }
}

where the main.xml is the following:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android";
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<ImageView
    android:id="@+id/weatherimg"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />
</LinearLayout>

Instead, if I insert the same image in the directory res/drawable of the
project and I use the following code the image is correctly viewed:

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);
        ImageView img = (ImageView) findViewById(R.id.weatherimg);

        //this function
        img.setImageDrawable(getResources().getDrawable(R.drawable.sereno));
    }

Have you some suggestion?

Thanks
Andrea

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to