2013-01-03 45 views
1

我目前在Android上工作,并且我创建了listview,它从URL加载图像。我已经通过下面的代码图像不是从列表视图上的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的隐形部分。也就是说,如果我在列表视图方法中有100个图像,一次只有10幅图像在屏幕上可见,这10幅图像不会在乞讨时加载,当我向下滚动时,另外10个不可见图像现在进入可见部分,并且这些图像现在已成功加载,再次向上滚动时,现在这些卸载的图像现在也加载了,这意味着它在屏幕上可见时不会加载。对不起,我的英文。希望,我已经详细解释过了。如何从URL中加载所有listview图像,而无需向下滚动/向上滚动。请帮助我。谢谢。

+0

你必须刷新列表View.Follow链接下面 http://stackoverflow.com/questions/2250770/how-to-refresh-android-listview – Warewolf

+1

@赫拉克勒斯你的方法不适合我。 – praba

+0

@praba使用延迟加载由Dhaval的答案给出或遵循此链接http://negativeprobability.blogspot.in/2011/08/lazy-loading-of-images-in-listview.html – Warewolf

回答

2

检查这个答案是帮助你:

1:https://stackoverflow.com/a/3068012/1168654

2:https://stackoverflow.com/a/8562313/1168654

如果你的应用程序有许多图像&也有记忆问题,那么你有以处理你的方式。 像使用LAZEY加载的listview中的下载图像。和其他图像使用像链接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'

+0

我想与第二链接。我会尽快更新。谢谢您的回答。 –

+1

我通过使用UniversalImageLoader.jar完成了这项工作,但我仍然不知道,这个问题的原因是什么。以前我用过“InputStream is =(InputStream)new URL(strPhotoUrl).getContent();”从URL加载图片,但现在我改变了,工作正常。谢谢。 –