tags:

views:

310

answers:

1

hello all

What I want to do is a database listview With a small image button and text on the right side The I want the small image to change with a URL given by A text file but I am stuck and the 2 hour rule is up

For(file lenght) So URL is www.site.com/images/(i++).png

+3  A: 

What you want to do is definitely possible, however you will need to manually fetch the image and set it on the ImageButton.

Here is a little method you can use to fetch an image:

private Bitmap fetchImage( String urlstr )
{
    try
    {
        URL url;
        url = new URL( urlstr );

        HttpURLConnection c = ( HttpURLConnection ) url.openConnection();
        c.setDoInput( true );
        c.connect();
        InputStream is = c.getInputStream();
        Bitmap img;
        img = BitmapFactory.decodeStream( is );
        return img;
    }
    catch ( MalformedURLException e )
    {
        Log.d( "RemoteImageHandler", "fetchImage passed invalid URL: " + urlstr );
    }
    catch ( IOException e )
    {
        Log.d( "RemoteImageHandler", "fetchImage IO exception: " + e );
    }
    return null;
}

Of course you will want to wrap this method in a thread (Using AsyncTask with SDK 1.5 or UserTask in SDK pre 1.5), then simply call:

myImageButton.setImageBitmap( bitmap );

I think this has answered your question, if not please elaborate further.

Casey