Searching a method like getResourcesID(int) - java

I'm searching a method that gives me the ID (int) from the Resource from a ImageView in my App. I don't know the name of the Image or something else. i only have an imageview and there is an Image from my Resources inside.
The reason is that i need it is to save it in my SQLite Database as an Integer.
Because later i will read this Data in my SQLite Database to use the method
ImageView.setImageResource((int) R.drawable.SavedPic).
I'm only a beginner in programming so it will not be the best way to do it but i coding the hole day and i hope that you can give me the right method.

There is no direct way to get the Image Resource Id from an ImageView. But there is a way to hold onto that using tags. So if you have an ImageView called imageView and an image resource called R.drawable.image you can do something like this:
imageView.setImageResource(R.drawable.image);
imageView.setTag(R.drawable.image);
And later when you want to get the resource Id associated with the ImageView you can fetch it using
int imageResourceId = (Integer) imageView.getTag();

Related

Sending Images Between Activities - Android (Kotlin/Java)

I have a class which encapsulates the information I want to pass over and it is parcelable. So I can pass its properties from one activity to another by using Intent.putExtra() method. But I cannot send images with it since images' sizes are larger than it should be (it doesn't matter whether they are Bitmap or ByteArray).
User downloads images from Firebase Storage and it is very likely that when user views an image, she won't see it again. So saving images in a cache-like storage isn't really necessary.
In Swift, I can do something like this:
// We are in currentViewController which is the activity that will send the image
let someNewViewController = NewViewController() // Create an instance of NewViewController class which is the activity that will receive image
someNewViewController.image = someImage // NewViewController class has a property called image, assign it an image from currentViewController
navigationController.pushViewController(someNewViewController, animated: True) // Go to someNewViewController activity
And then you can easily use image in the someNewViewController by accessing image property. When someNewViewController deallocated, image will be removed by garbage collection.
Is there a similar way in Kotlin/Java? Or is there an alternative to putExtra() that will allow large files to be transferred?
Thanks in advance!

How can I create a ListView of videos, and images?

How can I create a ListView of videos?
I explain myself a little better, I want to make an app with a listview that contains short videos.
I create an activity list_item where I want to put images and text. For example in the first list item I want you to put a thumbnail and a description, for example: horse accident and in the second list_item put another thumbnail with another description, for example: squirrel attack.
I know how to create a list view that shows the same image in all the list_items, but I don't know how to make a list view that contains different videos, images and text for each list_item.
The images, the video and are stored in the assets and raw folder, respectively.
Do you have any idea how to fix this?
Use this library for videos using ListView :
implementation 'cn.jzvd:jiaozivideoplayer:6.2.12'
use this link for documentation : https://github.com/lipangit/JiaoZiVideoPlayer

How to get the uri of the images stored in the phone and return them in a String[]

I am trying to create a custom gallery with a single select option. I've used the code provided by google docs to create a GridView that contains the images contained in drawable.
Now I want to change it by making the GridView show all the images stored in the phone.
To get all images from the phone you need to query the android.provider.MediaStore
First make sure you have the AndroidPermission.READ_EXTERNAL_STORAGE, then get the thumbnails for the grid.
Here is a simple way to do this:
HERE
Hope this helps.

How can I get the imagelevel of an ImageView?

In my app I'm using a few Imageviews with LevelListDrawables to be able to change then dynamically.
But now I want to know if I can read in which level the ImageView is stated, I set the level with setImageLevel() but there is no against hanging method to get the imagelevel.
So my question is: Is there a way to get the current imagelevel of an imageview?
You can't do it directly to the ImageView, but you can do this
imageView.getDrawable().getLevel()
That will do the trick, for further information the offical documentation for Drawable#getLevel()

How do I insert multiple image in Edit Text in android

I am trying to insert multiple images in one editText. I have used following code to attach image to EditText
txt = (EditText)findViewById(R.id.text);
Bitmap bitmap = BitmapFactory.decodeFile(attach);
Drawable drawable = new BitmapDrawable(bitmap);
txt.setBackgroundDrawable(drawable);
But the problem is it only attach one file and show, If i used array then only the last image is only show. at any how it only shows one Image. Is there any way to show multiple images in one Editbox. Thanks in advance.
Because you can only have one background.... if you want more then there is a layer Drawable which you can use and also you can put the button in a frame layout and add a couple of imageViews below/over it for the rest of the images.
But the best solution will probably be instead of having a couple of bitmaps to just make a single one in Photoshop or equivalent photo editing app and place that one.
According to docs: http://developer.android.com/reference/android/view/View.html#setBackgroundDrawable(android.graphics.drawable.Drawable)
You are not able to provide more than one Drawable item in argument
And I don't know if you understand what is .setBackgroundDrawable(d) method purpose, but it is not meant to be used for displaying images inside text but to set Background of EditText View.
So you're not inserting images in EditText but setting its background,
look for some Rich Text Edit components usable for Android
such as http://code.google.com/p/android-richtexteditor/
or others..
You can probably use a LayerDrawable with the constructor LayerDrawable(Drawable[] layers) to chain together several images and display them as an EditText's background, though as Marek said, I suspect you're looking for something other than setting images in the background.

Categories