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;
}
});
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) {
return null;
}
}