我有带有Imageview和textview的gridview,文本视图正确显示,并且图像需要花费一些时间才能从服务器加载,我的问题是当我向下滚动图像时,gridview中缺少图像,我正在使用volly NetworkImageView进行加载来自url的数据,这是我的gridview适配器
public class GridViewWordAdapter extends BaseAdapter {
private ImageLoader imageLoader;
private Context context;
private List<Word> movieItems;
LayoutInflater inflater;
public GridViewWordAdapter(Context context, List<Word> movieItems) {
this.context = context;
this.movieItems = movieItems;
}
@Override
public int getCount() {
return movieItems.size();
}
@Override
public Object getItem(int position) {
return movieItems.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
static class ViewHolderItem {
TextView textViewItem;
TextView textViewen;
TextView textViewar;
TextView textViewtag;
TextView textViewaudio;
NetworkImageView networkImageView;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View gridViewAndroid;
if (convertView == null) {
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
gridViewAndroid = inflater.inflate(R.layout.gridview_word_layout, null);
} else {
gridViewAndroid = (View) convertView;
}
TextView textViewen = (TextView) gridViewAndroid.findViewById(R.id.tv_word_en);
TextView textViewar = (TextView) gridViewAndroid.findViewById(R.id.tv_word_ar);
TextView textViewtag = (TextView) gridViewAndroid.findViewById(R.id.tv_word_tagoi);
TextView textViewaudio = (TextView) gridViewAndroid.findViewById(R.id.tv_audio);
NetworkImageView networkImageView = (NetworkImageView) gridViewAndroid.findViewById(R.id.android_gridview_word_image);
Word word = movieItems.get(position);
imageLoader = CustomVolleyRequest.getInstance(context).getImageLoader();
imageLoader.get(word.getImg(), ImageLoader.getImageListener(networkImageView,
R.mipmap.ic_launcher, android.R.drawable.ic_dialog_alert));
networkImageView.setImageUrl(word.getImg(), imageLoader);
textViewen.setText(word.getEnglish());
textViewar.setText(word.getArabic());
textViewtag.setText(word.getTagoi());
textViewaudio.setText(word.getAudio());
return gridViewAndroid;
}
}
在此先感谢
答案 0 :(得分:0)
可能的改变你必须作出是,
1.您正在viewholder和getview()中声明视图。仅在getview()中声明它们。
2. {% extends 'base.html' %}
{% load staticfiles %}
{% load embed_video_tags %}
{% block metadescription %}
{% if category %}
{{ category.description|truncatewords:155 }}
{% else %}
Welcome to the Cushion Store
{% endif %}
{% endblock %}
{% block title %}
{% if category %}
{{ category.name }} - Perfect Cushion Store
{% else %}
See Our Cushion Collection - Perfect Cushion
{% endif %}
{% endblock %}
{% block content %}
<div class="my_header_samples">
<br>
<br>
<br>
<div class="container">
<p class="my_samples_title">Paquete de muestras a S/10</p>
<p>192 reviews<i class="gold-star fas fa-star-half-alt"></i>
<i class="gold-star fas fa-star-half-alt"></i>
<i class="gold-star fas fa-star-half-alt"></i>
</p>
<div class="row">
<div class="text-center">
<a href="{% url 'shop:SamplePack' 'muestras' 'sample-pack' %}"
class="btn btn-azul text-white btn-block">Agregar al carrito</a>
</div>
</div>
</div>
</div>
<br>
<br>
<div class="container">
<br>
<br>
<br>
<p class="my_samples_subtitle text-center">O también puedes obtener tus muestras con tu diseño personalizado.</p>
<br>
<div class="row col-md-12">
{% for muestra in muestras %}
<div class="col-md-3">
<div class="text-center">
<a href="{{muestra.get_url }}"><img class="my_image_medium"
src="{{ muestra.image.url }}"
alt="{{ muestra.name }}"></a>
</div>
<p class="text-center">{{ muestra.name }}</p>
</div>
{% endfor %}
</div>
<br>
<br>
<div class="row col-md-12">
<p class="text-center">
{% video categoria_muestras.video as my_video %}
{% video my_video "medium" %}
{% endvideo %}
</p>
</div>
</div>
<br>
<br>
{% endblock %}
应是有效串URL格式。
3.使用其前景或背景图像,而不是仅使用R.mipmap.ic_launcher。
4. 收集完所有数据后,使用word.getImg()
。
希望它帮助。