问题描述
我想要做的是一个数据库列表视图用小图像按钮和文本的右侧在我想要的小图片来改变与给定的URL一个文本文件,但我坚持和2小时的规则是由
What I want to do is a database listviewWith a small image button and text on the right sideThe I want the small image to change with a URL given byA text file but I am stuck and the 2 hour rule is up
有关(文件lenght)因此,URL是www.site.com/images/(i ++)。png格式
For(file lenght)So URL is www.site.com/images/(i++).png
推荐答案
你想要做什么,绝对是可能的,但是你需要手动获取图像并在ImageButton的设置。
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;
}
当然,你会想在一个线程中包装这个方法(使用的AsyncTask 与SDK 1.5或<一href="http://$c$c.google.com/p/apps-for-android/source/browse/trunk/Photostream/src/com/google/android/photostream/UserTask.java"标题=UserTask>在SDK pre 1.5)UserTask ,则只需拨打:
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.
这篇关于是否有可能将图像从URL在Android的一个ImageButton的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!