Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

Java
@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


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

1 solution

Any one with suggestion please.?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900