2016-03-25 60 views
0

我想在我的彈出圖像從互聯網帶到節目,我想,以填補互聯網圖像彈出的ImageView的,這是我做了什麼ImageView的彈出請求互聯網圖像

private boolean userClicked = false; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.content_serviciosp); 

    iv = (ImageView) findViewById(R.id.publi); 
    bitmap = getBitmapFromURL("MY_URL"); 
    iv.setImageBitmap(bitmap); 





    final Button btnOpenPopup = (Button)findViewById(R.id.openpopup); 
     btnOpenPopup.setOnClickListener(new Button.OnClickListener() { 

      @Override 
      public void onClick(View arg0) { 
       LayoutInflater layoutInflater 
         = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE); 
       View popupView = layoutInflater.inflate(R.layout.popup, null); 
       final PopupWindow popupWindow = new PopupWindow(
         popupView, 
         ViewGroup.LayoutParams.WRAP_CONTENT, 
         ViewGroup.LayoutParams.WRAP_CONTENT); 

       Button btnDismiss = (Button) popupView.findViewById(R.id.dismiss); 
       btnDismiss.setOnClickListener(new Button.OnClickListener() { 

        @Override 
        public void onClick(View v) { 
         // TODO Auto-generated method stub 
         popupWindow.dismiss(); 
        } 
       }); 

       popupWindow.showAsDropDown(btnOpenPopup, 50, -30); 



      } 
     }); 
    new Handler().postDelayed(new Runnable() { 

     @Override 
     public void run() { 
      Random random = new Random(); 
      int x = random.nextInt(7) + 1; 
      if (!userClicked && x == 1 || x == 3|| x == 5) 
       btnOpenPopup.performClick(); 
     } 

    }, 100); 

    CustomList adapter = new CustomList(Agro.this, web, desc, tel, imageId, imageId3); 
    list = (ListView) 

      findViewById(R.id.lvlista); 

    list.setAdapter(adapter); 

    list.setOnItemClickListener(new AdapterView.OnItemClickListener() 

    { 

     @Override 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
      Toast.makeText(Agro.this, "Usted Clico en " + web[+position], Toast.LENGTH_SHORT).show(); 

      if (position == 0) { 

       Intent callIntent = new Intent(Intent.ACTION_CALL); 
       callIntent.setData(Uri.parse("tel:222222222222")); 
       startActivity(callIntent); 
      } 


     } 
    }); 
} 

public Bitmap getBitmapFromURL(String src) { 
    try { 
     URL url = new URL(src); 
     HttpURLConnection connection = (HttpURLConnection) url 
       .openConnection(); 
     connection.setDoInput(true); 
     connection.connect(); 
     InputStream input = connection.getInputStream(); 
     Bitmap myBitmap = BitmapFactory.decodeStream(input); 
     return myBitmap; 

    } catch (Exception e) { 
     // TODO: handle exception 
     e.printStackTrace(); 
     return null; 
    } 
} 

}

但似乎當我按下列表它崩潰,它不會把網上的圖像,在彈出的

感謝您的幫助

+0

請發佈包含崩潰的logcat輸出。 –

回答

0

我建議你使用凌空天秤座對於這樣的網絡資源。排球很有效率,像魅力一樣運作。

+0

我用這個witouth這樣的圖書館,你可以請幫助我們這個代碼?謝謝 – gioton

+0

http://www.androidhive.info/2014/05/android-working-with-volley-library-1/ – takrishna

+0

有一個視頻在上面的鏈接..這解釋了所有 – takrishna