Reputation: 2150
I'm trying to load images in a RecyclerView
.
It's working alright until I scroll left and right (horizontal RecyclerView
), some pictures disappear (the one at the edges) with the following error :
Volley: [3267] NetworkDispatcher.run: Unhandled exception java.lang.IllegalArgumentException: width and height must be > 0
Now here is my adapter class (I believe the problem is here) :
package com.rezadiscount.rezadiscount.adapter;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import com.android.volley.toolbox.NetworkImageView;
import com.rezadiscount.rezadiscount.R;
import com.rezadiscount.rezadiscount.activities.FragmentBusinessProfile;
import com.rezadiscount.rezadiscount.utilities.HTTPVolleyRequest;
import com.rezadiscount.rezadiscount.utilities.QuickstartPreferences;
import java.util.ArrayList;
//TODO Images disappear in list
/**
* Adapter of finding a business by category
*/
public class BusinessPictureAdapter extends RecyclerView.Adapter<BusinessPictureAdapter.CategoryViewHolder> {
private ArrayList<String> businessPictureList;
private Context con;
// Provide a suitable constructor (depends on the kind of dataset)
public BusinessPictureAdapter(ArrayList<String> businessPictureListP, Context conP) {
con = conP;
businessPictureList = businessPictureListP;
}
// Create new views (invoked by the layout manager)
@Override
public BusinessPictureAdapter.CategoryViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
// create a new view
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.business_picture_item, parent, false);
// set the view's size, margins, paddings and layout parameters
return new CategoryViewHolder((LinearLayout) v);
}
// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(CategoryViewHolder holder, int position) {
// - get element from your dataset at this position
// - replace the contents of the view with that element
holder.imageView.setImageUrl(QuickstartPreferences.URL_IMAGES + businessPictureList.get(position), HTTPVolleyRequest.getInstance(con).getImageLoader());
Log.d("CardView Text", "Image url" + QuickstartPreferences.URL_IMAGES + businessPictureList.get(position));
//holder.currentItem = items.get(position);
}
// Return the size of your dataset (invoked by the layout manager)
@Override
public int getItemCount() {
return businessPictureList.size();
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
// Provide a reference to the views for each data item
// Complex data items may need more than one view per item, and
// you provide access to all the views for a data item in a view holder
public class CategoryViewHolder extends RecyclerView.ViewHolder {
// each data item is just a string in this case
public NetworkImageView imageView;
public CategoryViewHolder(LinearLayout v) {
super(v);
imageView = (NetworkImageView) v.findViewById(R.id.business_picture);
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
}
}
Note : I've googled it and couldn't solve the problem so far. Any help is highly appreciated.
Upvotes: 0
Views: 1227
Reputation: 2150
Alright as Tranhieu suggested, I used Picasso and it now works. It's pretty simple to use and quite sexy, I recommend it. Now why volley didn't might be a different management of the cache, I won't look further.
Upvotes: 1