从适配器加载图像并将其显示在带有文本的列表视图中

时间:2013-02-08 13:57:21

标签: android android-asynctask loading-image

我不知道如何从之前发布的适配器类加载图像但我没有得到任何帮助解决问题的代码请通过异步帮助我代码请有人知道解决方案。我在同一个问题上挣扎了两天。

公共类NewsRowAdapter扩展了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;

    }

}

1 个答案:

答案 0 :(得分:0)

检查this以创建自定义ListView&amp;对于图片加载,请尝试LazyList