package com.example.day06_ex_02;
import java.io.FileInputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public class MyTask extends AsyncTask{
Bitmap bit;
@Override
protected Bitmap doInBackground(String... params) {
try {
//网上获取图片的地址
URL url=new URL("http://news.hhtc.edu.cn/uploads/20131101160529587.jpg");
HttpURLConnection conn=(HttpURLConnection) url.openConnection();
bit=BitmapFactory.decodeStream(conn.getInputStream());
} catch (Exception e) {
e.printStackTrace();
}
return bit;
}
@Override
protected void onPostExecute(Bitmap result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
ImageView tv=(ImageView) findViewById(R.id.iv_01);
tv.setImageBitmap(result);
}
}
public void start(View v){
new MyTask().execute();
}
}