欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

RXjava網(wǎng)絡(luò)獲取圖片數(shù)據(jù)的方法

 更新時(shí)間:2019年08月22日 08:52:28   作者:看得見的幸福  
這篇文章主要為大家詳細(xì)介紹了RXjava網(wǎng)絡(luò)獲取圖片數(shù)據(jù),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了RXjava網(wǎng)絡(luò)獲取圖片數(shù)據(jù)的具體代碼,供大家參考,具體內(nèi)容如下

RXjava

// An highlighted block
image = findViewById(R.id.tu);

  Observable.create(new ObservableOnSubscribe<Bitmap>() {
   @Override
   public void subscribe(ObservableEmitter<Bitmap> e) throws Exception {
    e.onNext(getBitmap());
   }
  })
    //設(shè)置數(shù)據(jù)在子線程中遍歷
    .subscribeOn(Schedulers.io())
    //設(shè)置圖片在主線程中加載
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(new Observer<Bitmap>() {
     @Override
     public void onSubscribe(Disposable d) {

     }

     @Override
     public void onNext(Bitmap bitmap) {
      image.setImageBitmap(bitmap);
     }

     @Override
     public void onError(Throwable e) {

     }

     @Override
     public void onComplete() {

     }
    });
  image.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View view) {
    Toast.makeText(MainActivity.this, "ee", Toast.LENGTH_SHORT).show();
   }
  });
  image.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View view) {

   }
  });

網(wǎng)絡(luò)獲取數(shù)據(jù)

// An highlighted block
//獲取網(wǎng)絡(luò)數(shù)據(jù)
 private Bitmap getBitmap() {
  String str = "https://b-ssl.duitang.com/uploads/blog/201406/16/20140616171020_TiEXR.thumb.700_0.jpeg";
  try {
   URL url = new URL(str);
   HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
   urlConnection.setRequestMethod("GET");
   urlConnection.setConnectTimeout(2000);
   urlConnection.connect();
   if(urlConnection.getResponseCode() == 200){
    return BitmapFactory.decodeStream(urlConnection.getInputStream());
   }
  } catch (MalformedURLException e) {
   e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
  }
  return null;
 }

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論