将WebService中的图像设置为AlertDialog中的图标 [英] Set image from WebService as icon in AlertDialog
本文介绍了将WebService中的图像设置为AlertDialog中的图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在制作一个应用程序,当用户长按一个列表项时,会弹出一个警告对话框,其中包含与listItem相关的一些信息。
我想从我的API提供的路径设置Icon。 TeamFlagIC在TeamsMapper类中,它包含图像路径。
这是我的onPostExecute方法。
i am currently making an app, in which , when user long presses an item of list it pops up an alert dialog with some info related to listItem.
I want to set Icon from path provided by my API. TeamFlagIC is in TeamsMapper class, which contains the path of image.
This is my onPostExecute Method.
@Override
protected void onPostExecute(Object result) {
if (progressDialog.isShowing()) {
progressDialog.dismiss();
}
String json = result.toString();
Gson gson = new Gson();
Type type = new TypeToken<List<TeamsMapper>>() {}.getType();
final ArrayList<TeamsMapper> pd = (ArrayList<TeamsMapper>) gson.fromJson(json, type);
dataAdapter = new TeamsCustomAdapter(Teams.this, pd);
listView.setAdapter(dataAdapter);
imageLoader = new ImageLoader(Teams.this);
final AlertDialog.Builder ImageAlertBuilder = new AlertDialog. Builder (Teams. this);
inflater = (LayoutInflater) (Teams.this).getSystemService
(LAYOUT_INFLATER_ SERVICE);
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View v,int position, long id) {
View layout = inflater.inflate(R.layout.popup_from_list,(ViewGroup) findViewById(R.id.linear_layout_popup));
imgViewDialogImage = (ImageView) layout.findViewById(R.id.img);
txtViewTeamsdata = (TextView) layout.findViewById(R.id.txtView);
imageLoader.DisplayImage(pd.get(position).TeamFlagFS,imgViewDialogImage);
String iurl = pd.get(position).TeamFlagIC;
bitMap = getBitmapFromURL(iurl);
drawable = new BitmapDrawable(getResources(),bitMap);
ImageAlertBuilder.setIcon(drawable); //<---
ImageAlertBuilder.setTitle(" "+ pd.get(position).TeamName);
ImageAlertBuilder.setView(layout);
ImageAlertBuilder.create();
ImageAlertBuilder.show();
return false;
}
});
来自Url的图片下载器
Image downloader from Url
public static 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 (IOException e) {
// Log exception
return null;
}
}
推荐答案
请提出任何建议。?
这篇关于将WebService中的图像设置为AlertDialog中的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文