Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 未从listview上的URL加载图像_Android_Url_Listview_Imageview - Fatal编程技术网

Android 未从listview上的URL加载图像

Android 未从listview上的URL加载图像,android,url,listview,imageview,Android,Url,Listview,Imageview,我目前正在Android上工作,我创建了从URL加载图像的listview。我通过以下代码实现了这一点 InputStream is = (InputStream) new URL("http://ka.35pk.com/uploadfiles/gamepic/090830121252.jpg").getContent(); Drawable d = Drawable.createFromStream(is, "pic name"); imageview.setImageDrawable(d)

我目前正在Android上工作,我创建了从URL加载图像的
listview
。我通过以下代码实现了这一点

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上有100个图像,意味着一次只有10个图像在屏幕上可见,这10个图像在begging时无法加载,当我向下滚动时,另10个不可见的图像出现在可见部分,并且这些图像现在成功加载,当我向上滚动时,现在卸载的图像也加载了,这意味着,当它在屏幕上可见时无法加载。对不起,我的英语。希望,我已经详细解释了。如何从URL加载所有
listview
图像而不使用向下/向上滚动。请帮帮我。谢谢

检查此答案,它对您有帮助:

  • (1)

  • (2)
如果你的应用程序有很多图像,而且内存也有问题,那么你必须以一种全新的方式处理

类似于使用延迟加载在listview中下载图像。对于其他图像,请使用另一种方式,如链接2

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

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'

您必须刷新列表视图。请遵循@Hercules下面的链接。您的方法不适用于我。@praba使用Dhaval回答中给出的延迟加载,或者遵循我正在尝试的第二个链接。我会很快更新。谢谢你的回答。我是通过使用UniversalImageLoader.jar完成这项工作的,但是我仍然不知道,这个问题的原因是什么。以前我使用“InputStream is=(InputStream)new URL(strPhotoUrl).getContent();”从URL加载图像,但现在我做了更改,工作正常。谢谢