找传奇、传世资源到传世资源站!

android_加载_网络图片_示例源码_

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

简单的网络图片查看
android_加载_网络图片_示例源码_ Android平台开发-第1张android_加载_网络图片_示例源码_ Android平台开发-第2张
public void visit(View view) {
et_imageAdress = (EditText) findViewById(R.id.et_imageAdress);
final String imagetAdress = et_imageAdress.getText().toString();
imageView = (ImageView) findViewById(R.id.imageView);
if(TextUtils.isEmpty(imagetAdress)) {
Toast.makeText(this, "访问路径不能为空!", 0).show();
} else {
new Thread(){
public void run() {
try {
URL url = new URL(imagetAdress);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
if(conn.getResponseCode()==200) {
InputStream is = conn.getInputStream();
Bitmap bitmap= BitmapFactory.decodeStream(is);
//imageView.setImageBitmap(bitmap);
Message msg = Message.obtain();
msg.what = IMAGE_VIEW;
msg.obj = bitmap;
Log.i(Tag, "消息接收到了1。。。");
handler.sendMessage(msg);
}else {
Message msg = Message.obtain();
msg.what = OHTER_ERROR;
handler.sendMessage(msg);
//Toast.makeText(MainActivity.this, "123!", 0).show();
}
} catch (MalformedURLException e) {
//Toast.makeText(MainActivity.this, "访问路径错误!", 0).show();
Message msg = Message.obtain();
msg.what = PATH_ERROR;
handler.sendMessage(msg);
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
//Toast.makeText(MainActivity.this, "访问网络失败!", 0).show();
Message msg = Message.obtain();
msg.what = INTERNET_ERROR;
handler.sendMessage(msg);
e.printStackTrace();
}
}
}.start();
}
}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复