滚动列表后失去从NetworkImageView图像上下 [英] Losing images from NetworkImageView after Scrolling list up-down
问题描述
我有一个的ListView ,抓住使用排球的Json与之相关的图片新闻。 首先它加载一切,但是当我滚动列表,回来,有时显示图像,有时没有。滚动经过2-3次列表视图
失去每一个形象。同样的程序完美的作品我的测试应用程序(随着动作条的标签只有),所以我不知道发生了什么。谢谢adavance您的时间。
注意:我用 MySingleton
和 LruBitmapCache
从开发者的网站。我的应用程序的界面类似于像Play商店即导航抽屉标签。我搜索这样的问题,但没有找到直接的答案。很抱歉,如果这是愚蠢的问题要问这里。
如果我用ViewHolder那么这个问题得到解决,但我无法以编程方式删除NetworkImageView如果网址不存在。 我不知道希望有一个没有图像的行图像占位符
下面是我为行布局文件:
< RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:填充=8DP>
< com.android.volley.toolbox.NetworkImageView
机器人:ID =@ + ID / cat_thumbnail
机器人:layout_width =80dp
机器人:layout_height =80dp
机器人:layout_alignParentLeft =真
机器人:layout_marginRight =8DP
/>
<的TextView
机器人:ID =@ + ID / cat_title
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:TEXTSIZE =16DP
机器人:layout_alignTop =@ ID / cat_thumbnail
机器人:layout_toRightOf =@ ID / cat_thumbnail
/>
<的TextView
机器人:ID =@ + ID / cat_paper
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ ID / cat_title
机器人:layout_marginTop =1dip
机器人:layout_toRightOf =@ + ID / cat_thumbnail
机器人:TEXTSIZE =15dip/>
适配器类
私人活动的活动;
私人LayoutInflater充气;
私人列表< NewsArticles> newsArticlesItems;
ImageLoader的ImageLoader的;
公共NewsAdapter(活动活动,列表和LT; NewsArticles> newsArticlesItems)
{
this.activity =活动;
this.newsArticlesItems = newsArticlesItems;
}
@覆盖
公众诠释getCount将(){
返回newsArticlesItems.size();
}
@覆盖
公共对象的getItem(INT位置){
返回newsArticlesItems.get(位置);
}
@覆盖
众长getItemId(INT位置){
返回的位置;
}
@覆盖
公共查看getView(INT现在的位置,查看convertView,ViewGroup中的ViewGroup){
如果(充气== NULL)
{
充气=(LayoutInflater)activity.getSystemService(activity.LAYOUT_INFLATER_SERVICE);
}
如果(convertView == NULL)
{
convertView = inflater.inflate(R.layout.cat_list_items,NULL);
}
如果(ImageLoader的== NULL)
ImageLoader的= MySingleton.getInstance(活性).getImageLoader();
//文章图片
NetworkImageView缩略图=(NetworkImageView)convertView.findViewById(R.id.cat_thumbnail);
//文章标题
TextView的标题=(TextView中)convertView.findViewById(R.id.cat_title);
//报纸名称
TextView的newspaperName =(TextView中)convertView.findViewById(R.id.cat_paper);
//
如果(!URLUtil.isValidUrl(newsArticlesItems.get(位置).getThumbnailUrl()))
{
thumbnail.setVisibility(View.GONE);
}
/*if(newsArticlesItems.get(postion).getThumbnailUrl()==)
{
thumbnail.setVisibility(View.GONE);
} * /
其他
{
thumbnail.setImageUrl(newsArticlesItems.get(位置).getThumbnailUrl(),ImageLoader的);
}
title.setText(newsArticlesItems.get(位置).getTitle());
newspaperName.setText(newsArticlesItems.get(位置).getNewspaperName());
返回convertView;
}
试试这样在else块
其他
{
thumbnail.setVisibility(View.VISIBLE); //添加此
thumbnail.setImageUrl(newsArticlesItems.get(位置).getThumbnailUrl(),ImageLoader的);
}
I have a ListView that grabs news with images associated with it using Volley Json. At first it loads everything but when i scroll the list and come back, it sometimes shows images and sometimes not. After scrolling 2-3 times listview
loses every image. Same procedure works perfectly with my test app (With Actionbar Tabs Only) so i don't know what is happening. Thanks in adavance for your time.
Note: I use MySingleton
and LruBitmapCache
from Developers site. My app's GUI is similar like Play Store i.e Navigation Drawer with Tabs. I searched problem like this but found no direct answer. Sorry if it is silly question to ask here.
If I use ViewHolder then that problem gets resolved but I am unable to remove NetworkImageView programmatically if URL is not there. I don't want to have placeholder image for row that doesn't have Image
Here is my layout file for row:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp">
<com.android.volley.toolbox.NetworkImageView
android:id="@+id/cat_thumbnail"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_marginRight="8dp"
/>
<TextView
android:id="@+id/cat_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16dp"
android:layout_alignTop="@id/cat_thumbnail"
android:layout_toRightOf="@id/cat_thumbnail"
/>
<TextView
android:id="@+id/cat_paper"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/cat_title"
android:layout_marginTop="1dip"
android:layout_toRightOf="@+id/cat_thumbnail"
android:textSize="15dip" />
Adapter class
private Activity activity;
private LayoutInflater inflater;
private List<NewsArticles> newsArticlesItems;
ImageLoader imageLoader;
public NewsAdapter(Activity activity, List<NewsArticles> newsArticlesItems)
{
this.activity = activity;
this.newsArticlesItems = newsArticlesItems;
}
@Override
public int getCount() {
return newsArticlesItems.size();
}
@Override
public Object getItem(int location) {
return newsArticlesItems.get(location);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int postion, View convertView, ViewGroup viewGroup) {
if(inflater == null)
{
inflater = (LayoutInflater) activity.getSystemService(activity.LAYOUT_INFLATER_SERVICE);
}
if(convertView == null)
{
convertView = inflater.inflate(R.layout.cat_list_items, null);
}
if (imageLoader == null)
imageLoader = MySingleton.getInstance(activity).getImageLoader();
//Article image
NetworkImageView thumbnail = (NetworkImageView) convertView.findViewById(R.id.cat_thumbnail);
//Article title
TextView title = (TextView) convertView.findViewById(R.id.cat_title);
//Newspaper Name
TextView newspaperName = (TextView) convertView.findViewById(R.id.cat_paper);
//
if(!URLUtil.isValidUrl(newsArticlesItems.get(postion).getThumbnailUrl()))
{
thumbnail.setVisibility(View.GONE);
}
/*if(newsArticlesItems.get(postion).getThumbnailUrl()=="")
{
thumbnail.setVisibility(View.GONE);
}*/
else
{
thumbnail.setImageUrl(newsArticlesItems.get(postion).getThumbnailUrl(), imageLoader);
}
title.setText(newsArticlesItems.get(postion).getTitle());
newspaperName.setText(newsArticlesItems.get(postion).getNewspaperName());
return convertView;
}
Try like this in else block
else
{
thumbnail.setVisibility(View.VISIBLE);//add this
thumbnail.setImageUrl(newsArticlesItems.get(postion).getThumbnailUrl(), imageLoader);
}
这篇关于滚动列表后失去从NetworkImageView图像上下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!