Issue
I have saved my drawables in an integer array in a resource file but when i try reading it and loading it using the glide library i am unable to dispaly an image.
Adapter
public class CuisineAdapter extends RecyclerView.Adapter<ViewHolder_Cuisine> {
private Context context;
private TypedArray pictures;
private ArrayList<Integer> images;
public CuisineAdapter(Context context) {
this.context = context;
this.images = new ArrayList<>();
/*images.add(R.drawable.africa);
images.add(R.drawable.bahamas);
images.add(R.drawable.brazil);
images.add(R.drawable.china);
images.add(R.drawable.denmark);
images.add(R.drawable.france);
images.add(R.drawable.germany);
images.add(R.drawable.great_britain);
images.add(R.drawable.greece);
images.add(R.drawable.india);
images.add(R.drawable.ireland);
images.add(R.drawable.israel);
images.add(R.drawable.italy);
images.add(R.drawable.japan);
images.add(R.drawable.korea);
images.add(R.drawable.mexico);
images.add(R.drawable.russia);
images.add(R.drawable.spain);
images.add(R.drawable.thailand);
images.add(R.drawable.united_arab_emirates);
images.add(R.drawable.united_states_of_america);
images.add(R.drawable.vietnam);*/
pictures = context.getResources().obtainTypedArray(R.array.country_flags);
Log.i("data", pictures.toString() + "");
}
@Override
public ViewHolder_Cuisine onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View view = inflater.inflate(R.layout.cuisine_type, parent, false);
return new ViewHolder_Cuisine(view);
}
@Override
public void onBindViewHolder(final ViewHolder_Cuisine holder, int position) {
int image = images.get(position);
Glide.with(context)
.load(image)
.override(150, 150)
.into(holder.getImageView());
//holder.getImageView().setImageResource(image);
}
@Override
public int getItemCount() {
return images.size();
}
}
If i use holder.getImageView().setImageResource(image); instead of glide everything works well and i can display the image but this takes a lot of memory so i wanted to use glide.
<integer-array name="country_flags">
<item>@drawable/africa</item>
<item>@drawable/bahamas</item>
<item>@drawable/brazil</item>
<item>@drawable/china</item>
<item>@drawable/denmark</item>
<item>@drawable/france</item>
<item>@drawable/germany</item>
<item>@drawable/great_britain</item>
<item>@drawable/greece</item>
<item>@drawable/india</item>
<item>@drawable/ireland</item>
<item>@drawable/israel</item>
<item>@drawable/italy</item>
<item>@drawable/japan</item>
<item>@drawable/korea</item>
<item>@drawable/mexico</item>
<item>@drawable/russia</item>
<item>@drawable/spain</item>
<item>@drawable/thailand</item>
<item>@drawable/united_arab_emirates</item>
<item>@drawable/united_states_of_america</item>
<item>@drawable/vietnam</item>
</integer-array>
I tried using typed array but that for unsuccessful so i shifted to an arraylist
Solution
The problem i realized is that glide loads only raster images and not vector images yet,so instead i used a vector image library to load vector images in my app.
Sharp Vector Image Loading Library
Answered By - Jude Fernandes
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.