photo_seeking

public class MainActivity extends Activity
{
private EditText et_path;
private ImageView iv;
private Handler handler=new Handler(){
	public void handMessage(android.os.Message msg)
	{
		Bitmap bitmap=(Bitmap) msg.obj;
		iv.setImageBitmap(bitmap);
	};
};
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		et_path=(EditText) findViewById(R.id.et_path);
		iv=(ImageView) findViewById(R.id.iv);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu)
	{
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	public void click(View v){
	new Thread(){
		public void run(){
			
		};}.start();
	try
	{
		String path=et_path.getText().toString().trim();
		URL url=new URL(path);
		HttpURLConnection conn=(HttpURLConnection) url.openConnection();
		conn.setRequestMethod("GET");
		conn.setConnectTimeout(4000);
		int code=conn.getResponseCode();
		if(code==200){
		InputStream in	=conn.getInputStream();
		Bitmap bitmap=BitmapFactory.decodeStream(in);
		//iv.setImageBitmap(bitmap);
		Message msg=Message.obtain();
		msg.obj=bitmap;
		handler.sendMessage(msg);
		}
	} catch (Exception e)
	{
		e.printStackTrace();
	}
	}

}


<ImageView
        android:id="@+id/iv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:background="@drawable/ic_launcher" />

    <EditText
        android:id="@+id/et_path"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="http://news.baidu.com/resource/img/logo_news_276_88.png?date=20150104"
        android:layout_gravity="center_horizontal"
        android:ems="10"
        android:hint="请输入图片的路径" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="click"
        android:layout_gravity="center_horizontal"
        android:text="浏览" />


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值