来自URL Android的java刷新图像视图
我需要一些帮助。我想刷新从安卓应用程序中的URL加载的ImageView。我试着用定时器,但没用。有什么想法吗
我在主要活动中有以下代码:
public class Imagens extends Activity {
private ImageView imagem;
private Bitmap bit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_imagens);
imagem=(ImageView) findViewById(R.id.imageView);
bit=getBitmapFromURL("http://www.onlinedegrees.org/wp-content/uploads/安卓1.jpg");
imagem.setImageBitmap(bit);
}
public Bitmap getBitmapFromURL(String src){
try{
URL url = new URL(src);
HttpURLConnection connection= (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
}
catch (Exception e){
e.printStackTrace();
return null;
}
}
}
在AndroidManifest中使用:
uses-permission 安卓:name="安卓.permission.INTERNET"
允许internet连接
# 1 楼答案
我可以推荐另一种像魅力一样工作的方式:安卓查询
你可以从here下载这个JAR文件
例如:
它非常快速和准确,使用它你可以找到更多的功能,比如加载时的动画,获取位图(如果需要)等等