-1

I have no idea about how to load images from adapter class also posted previously but i didn't get any help with the code solving the issue please help me with the code through async please someone if knows the solution. Its been two days am struggling with the same issue.

public class NewsRowAdapter extends ArrayAdapter {

    /*private DisplayImageOptions options;

    ImageLoader imageLoader;*/

    Bitmap bitmap = null;

    private Activity activity;

    private List<Item> items;

    private Item objBean;

    private int row;

    public NewsRowAdapter(Activity act, int resource, List<Item> arrayList) 
    {

        super(act, resource, arrayList);

        this.activity = act;

        this.row = resource;

        this.items = arrayList;

        /*options = new DisplayImageOptions.Builder().showStubImage(R.drawable.blank).showImageForEmptyUrl(R.drawable.blank).cacheInMemory().cacheOnDisc().build();

        imageLoader = ImageLoader.getInstance();
                */


    }




    @Override
    public View getView(final int position, View convertView, ViewGroup parent)
    {
        View view = convertView;

        final ViewHolder holder;

        if (view == null) 
        {

            LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            view = inflater.inflate(row, null);

            holder = new ViewHolder();

            view.setTag(holder);

        } else 
        {
            holder = (ViewHolder) view.getTag();
        }

        if ((items == null) || ((position + 1) > items.size()))

            return view;

        objBean = items.get(position);

        holder.tvTitle = (TextView) view.findViewById(R.id.tvtitle);

        holder.tvDesc = (TextView) view.findViewById(R.id.tvdesc);

        holder.tvDate = (TextView) view.findViewById(R.id.tvdate);

        holder.imgView = (ImageView) view.findViewById(R.id.image);

        holder.pbar = (ProgressBar) view.findViewById(R.id.pbar);

        if (holder.tvTitle != null && null != objBean.getTitle() && objBean.getTitle().trim().length() > 0) 
        {
            holder.tvTitle.setText(Html.fromHtml(objBean.getTitle()));
        }
        if (holder.tvDesc != null && null != objBean.getDesc() && objBean.getDesc().trim().length() > 0)
        {
            holder.tvDesc.setText(Html.fromHtml(objBean.getDesc()));
        }
        if (holder.tvDate != null && null != objBean.getPubdate() && objBean.getPubdate().trim().length() > 0)
        {
            holder.tvDate.setText(Html.fromHtml(objBean.getPubdate()));
        }
        if (holder.imgView != null) 
        {
            if (null != objBean.getLink() && objBean.getLink().trim().length() > 0) 
            {
                final ProgressBar pbar = holder.pbar;

                pbar.setVisibility(View.INVISIBLE);


                //---------CHANGES MADE FOR LOADING IMAGE----------//

                Log.d("IMAGE NULL----------", objBean.getLink());







                class ImageLoading extends AsyncTask<String, Void, Bitmap>
                {



                    @Override
                    protected Bitmap doInBackground(String... urls) 
                    {


                        return null;
                    }

                    @Override
                    protected void onPostExecute(Bitmap result) 
                    {

                        super.onPostExecute(result);
                    }






                }



                /*imageLoader.init(ImageLoaderConfiguration.createDefault(activity));


                {
                    imageLoader.displayImage(objBean.getLink(), holder.imgView, options, new ImageLoadingListener()
                    {
                                @Override
                                public void onLoadingComplete() 
                                {
                                    pbar.setVisibility(View.INVISIBLE);

                                }

                                @Override
                                public void onLoadingFailed() 
                                {
                                    pbar.setVisibility(View.INVISIBLE);
                                }

                                @Override
                                public void onLoadingStarted()
                                {
                                    pbar.setVisibility(View.VISIBLE);

                                }
                    });
                } */




            } else 
            {
                holder.imgView.setImageResource(R.drawable.ic_launcher);
            }
        }




        return view;
    }







    public class ViewHolder
    {
        public TextView tvTitle, tvDesc, tvDate;

        public ImageView imgView;

        public ProgressBar pbar;

    }

}
ayansinha
  • 85
  • 1
  • 12

1 Answers1

0

Check this for creating custom ListView & for image loading try LazyList.

Arun Badole
  • 10,977
  • 19
  • 67
  • 96
  • could any one please solve the question for me please. I couldn't find a way to solve it. How to put asynctask inside adapter and also inside getView() method. – ayansinha Feb 11 '13 at 05:37
  • First check how to create custom Listview. – Arun Badole Feb 12 '13 at 07:49
  • Ok So, i think i have to find some jar to load the images in background ryt. And yes have also seen some examples of custom list view with text and images. – ayansinha Feb 15 '13 at 09:25
  • please if any one could help me in loading images on background, may be asynctask then i would be very grateful... – ayansinha Feb 15 '13 at 20:00
  • Ayan LazyList is used for loading images in background.Try it. – Arun Badole Feb 18 '13 at 05:14
  • yes it worked and even it is also loading the images in background and then it is being displayed in the listview. Thankyou@AB1209 I really appreciate your help. – ayansinha Feb 18 '13 at 08:30