1

我目前正在使用 Android,并且我创建listview了从 URL 加载图像的程序。我通过以下代码实现了这一点

InputStream is = (InputStream) new URL("http://ka.35pk.com/uploadfiles/gamepic/090830121252.jpg").getContent();

Drawable d = Drawable.createFromStream(is, "pic name");
imageview.setImageDrawable(d); 

listview我向下滚动listview一次之前,图像不会加载。但它可以正确加载到listview. 即,如果我在 listview 上有 100 张图像,意味着一次只有 10 张图像在屏幕上可见,这 10 张图像无法在乞求时加载,当我向下滚动时,另外 10 张不可见图像现在出现在可见部分,并且这些图像现在已成功加载,当我再次向上滚动时,现在那些已卸载的图像现在也已加载,这意味着它在屏幕上可见时无法加载。对不起我的英语。希望,我已经详细解释了。如何在listview不使用向下/向上滚动的情况下从 URL 加载所有图像。请帮助我。谢谢。

4

1 回答 1

2

检查此答案对您有帮助:

如果您的应用程序有很多图像并且还存在内存问题,那么您必须以自己的方式处理。

就像使用延迟加载在列表视图中下载图像一样。对于其他图像,请使用另一种方式,例如链接 2。

对于您的滚动问题,请检查您getView()在适配器中添加的代码,如下所示:

public class ListViewAdapter extends BaseAdapter {

        private LayoutInflater mInflater;

        public ListViewAdapter(Context con) {
            // TODO Auto-generated constructor stub
            mInflater = LayoutInflater.from(con);
        }

        public int getCount() {
            // TODO Auto-generated method stub
            return SoapParser.title_date.size();
        }

        public Object getItem(int position) {
            // TODO Auto-generated method stub
            // return product_id1.size();
            return position;
        }

        public long getItemId(int position) {
            // TODO Auto-generated method stub
            // return product_id1.get(position).hashCode();
            return position;
        }

        public View getView(final int position, View convertView,
                ViewGroup parent) {
            // TODO Auto-generated method stub
            final ListContent holder;
            View v = convertView;
            if (v == null) {
                v = mInflater.inflate(R.layout.row_tb, null);
                holder = new ListContent();

                holder.date = (TextView) v.findViewById(R.id.textView1);
                holder.actual = (TextView) v.findViewById(R.id.textView2);
                holder.targate = (TextView) v.findViewById(R.id.textView3);

                v.setTag(holder);
            } else {

                holder = (ListContent) v.getTag();
            }



            holder.date.setId(position);
            holder.actual.setId(position);
            holder.targate.setId(position);

            holder.date.setText(" " + SoapParser.title_date.get(position));
            holder.actual.setText(" " + SoapParser.title_actual.get(position));
            holder.targate
                    .setText(" " + SoapParser.title_targate.get(position));

            return v;
        }
    } 

如果您在布局中使用任何其他视图,请制作它android:focusable='false'

于 2013-01-03T07:33:23.113 回答