我想在我的弹出窗口中显示从互联网上带来的图像,我想用互联网图像填充弹出窗口的图像视图,这就是我所做的
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 :(得分:0)
我建议您使用排球库来获取此类网络资源。排球很有效率,就像一个魅力。