How to access images and background colours in RecyclerView - onBindViewHolder - android

I'm trying to access my background colours and images for onBindViewHolder method.
Images are in res.mipmap folder after I created new Image assets.
Colours are in res.values.colours.xml file
Thanks in advance for help.
for exact code see image:
https://i.stack.imgur.com/h7Gq4.jpg

if you want to access resources, you can use view's context.
holder.view.resources.getColor(id)
holder.view.resources.getDrawable(id)

Related

Android how to load Image file with different extension using Picasso

This is a different situation. I want to load a image file which has stored with different extension like 'photo.xyz' instead of 'photo.jpg or photo.png' using Picasso. to avoid image from gallery i am storing image like this. Please help me is there any option to show like this.
Neither Picasso nor Android (which does the actual image decoding) cares what the file name is. It can be anything. The type of the image is always determined from the first few bytes of the actual image data.
As a small workaround you can programmatically put .nomedia file into your app folder to prevent images to be cached by mediaserver and displayed in a Gallery app.

Android setThumb(drawable) variable type?

All,
I'm trying to dynamically change the image displayed on the thumb of the seekbar in java, and came across the setThumb method. I have a .png file under res/drawable, but can't find the right way to refer to that .png file using setThumb(). Do any of you know how to do it?
Best and Thanks in Advance!
You need to create a drawable from your resource.
Drawable mypicture= getResources().getDrawable(R.drawable.mypicture);

How to swap images dynamically - wrong image showing

I need to change the source of an ImageView dynamically. I have a whole bunch of them with the same names, stored in their different dpi directories (drawable-hdpi etc) under res/. For this I've been using ImageView's setImageResource() and passing it a value from an array of resource IDs I've created at runtime like so:
decorations = new int[]{
R.drawable.bird1,
R.drawable.flower2,
R.drawable.bird3,
..etc};
Anyway, for some reason, the 6th image gets corrupted into an alternative image used for other things, not one in the resources list.
What on earth is going on?
Turns out I had a corrupt/incorrect image or the image was in the wrong directory or something. Still, strange that it decided to just display the next image in the directory rather than just crashing with an Exception or something.

How to pick image from particular folder, say sdcard/mypics?

How to pick image from particular folder, say sdcard/mypics?
i can recommend the gridview tutorial.
you will have to modify the code a bit to get the resource into an array before showing the gridview. but therefore you can use the BitmapFactory class.

Adding images into array of an Android Application

I want to display the images in my Application added to my "raw" folder of the Eclipse as it gets started.
How do I add those particular images to an Array and rotate the loop until all the Images are displayed?
Can anyone help me for this?
Check out Android's frame animation. I think it does exactly what you want.
http://developer.android.com/guide/topics/graphics/2d-graphics.html#frame-animation

Categories

Resources