我正在尝试使用Volley的ImageLoader实现Gallery元素。在接下来的请求中,我收到一个列表,其中包含一些将在图库中显示的网址。我的问题是Gallery没有显示任何内容。提前谢谢。
RestApiAdapter.getImages("Food", new RestApiAdapter.RestApiCallBack<List<String>>() {
@Override
public void execute(List<String> object) {
GaleriaAdapter gAdapter = new GaleriaAdapter(foodFragmentView.getContext());
gAdapter.setImages(object);
((Gallery) foodFragmentView.findViewById(R.id.gallery)).setAdapter(gAdapter);
}
});
现在适配器
import com.android.volley.toolbox.ImageLoader;
...
@Override
public View getView(int position, View convertView, ViewGroup parent) {
String url = (String) getItem(position);
ImageLoader imgLoader = VolleyRequest.getInstance(null).getImageLoader();
NetworkImageView imgView = new NetworkImageView(context);
imgView.setImageUrl(url, imgLoader);
return imgView;
}
答案 0 :(得分:0)
在将适配器添加到Grid之后是notifyDataSetChange()吗?
gAdapter.notifyDataSetChanged();
答案 1 :(得分:0)
我设法在一段时间后找出问题。基本上它错过了我自己假设的请求
@Override
public View getView(int position, View convertView, ViewGroup parent) {
String url = (String) getItem(position);
NetworkImageView imgView = new NetworkImageView(context);
ImageLoader imgLoader = VolleyRequest.getInstance(null).getImageLoader();
// This line of code
imgLoader.get(url, ImageLoader.getImageListener(imgView, LOADING_IMG, ERROR_IMG));
imgView.setImageUrl(url, imgLoader);
return imgView;
}
来源:http://www.truiton.com/2015/03/android-volley-imageloader-networkimageview-example/