Rathakrishnan Ramasamy
Rathakrishnan Ramasamy

Reputation: 1612

Image is not loading from URL on listview

I am Currently working on Android, and I created listview that loads Images from URL. I have achieved this by following code

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

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

In the listview the image is not loading till I scroll down the listview once. But it can loaded correctly on invisible part of listview. ie , if I have 100 images on listview means, only 10 images have visible on the screen at a time, these 10 images coudn't load at begging, when I scroll down, another 10 invisible images now come to the visible part, and those images are loaded successfully now, again when I scroll up , now those unloaded images also loaded now, which means that, it coudn't be loaded when it was visible on the screen. Sorry for my English.Hope, I have explained in details. How can I load all the listview images from URL without using scroll down/up. kindly help me. thanks.

Upvotes: 1

Views: 1139

Answers (1)

Dhaval Parmar
Dhaval Parmar

Reputation: 18978

Check this answer it is help you:

and

If your app have many image & also there is memory issue then you have to handle you owen way.

Like download image in listview using lazy loading. and for other images use another way like link 2.

for your scrolling problem check your getView() code in adapter add like below:

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

if you are use any other view in layout then make it android:focusable='false'

Upvotes: 2

Related Questions