图片在线查看
程序开发
2023-09-02 19:05:44
实验结果
核心代码
public class MainActivity extends Activity
{public EditText edtext; public ImageView image; public NetWorkUtils netWorkUtils; private Handler handler; public Bitmap bm; public static final int TEXT = 1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.activity_main); edtext = (EditText) findViewById(R.id.editText1); image = (ImageView) findViewById(R.id.imageView1); netWorkUtils = new NetWorkUtils(this); handler = new Handler(){public void handleMessage(Message msg){super.handleMessage(msg);switch (msg.what){case TEXT:image.setImageBitmap(bm);// 设置显示的文本break;default:break;}}}; } 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 sendHttp(View v){ boolean flag = netWorkUtils.setActiveNetWork(); if(flag){final String path = edtext.getText().toString(); if(TextUtils.isEmpty(path)){ Toast.makeText(MainActivity.this, "空地址或地址错误", Toast.LENGTH_LONG).show(); }else{ new Thread(new Runnable() { @Override public void run() { bm = HttpUtils.sendGets(path); handler.sendEmptyMessage(TEXT); } }).start(); } } }
}
标签:
相关文章
-
无相关信息