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;
    }
}

}

但当我按下列表时,它似乎崩溃了,它不会把在线图像放在弹出的中

感谢的帮助

我建议您对此类网络资源使用截击库。沃尔利效率很高,工作很有魅力。

最新更新