How to get the src from an ImageButton in Android? - android

I'm building the Activity to take information on the users pet and make a sqlite database entry with it. I want to be able to take a picture and store the src as one of the rows in the entry.
I currently have an ImageButton displaying a default picture from drawable, but how do I extract the src from the ImageButton?
I figure if I can do that then it'll be easy to make the button clickable so the user can set their own (then when they hit the save button, it'll grab the src of the new pic instead, otherwise if they don't click it the default pic will get saved)

Please Check the Below answer may be helps you.
Bitmap bitmap = ((BitmapDrawable)imagebutton.getDrawable()).getBitmap();

Related

How can I take the Multiple Gallery images into the Edit Text field Randomly

In my project I am try to pick the Gallery images and Emoticons into the Edit Text, I want like chat application. I need to pick the multiple Gallery images and add into the Edit Text field here with I attach my example image
You cant type messages with images inside the edittext for that fact that it wont scroll up or scroll left when editText is full.
solution:
what you need to do is create a string equivalent of the image
example:
:) = for happy face
:( = sad face
etc.
rr:)tttt:(
After you hit enter you can then parse your string and check for the emoticons in string form and delete it then replace it with picture.

add Information(text or csv) to image in android

I am trying to add few things like names, places to images. The idea is to have them sorted according to name or place when the users uses it.
I have the code working to take pictures and save it to the Phone's memory.
How can i add this Tag of information in my code?
Or even how can i add metadata to an image??
Off the top of my head, what you could do is create a database and have in three fields:
Names
Places
Image path
Use a GridView to show the images in your app(and load them images from the database). On GridView ItemClick you could prompt the user to add in tags into the image, later on you could use these fields to sort the image in you application.
Hope this helps.
I found what i was looking for we can add extra information to an image using ExifInterface. Thanks

Android: How to change a button so that it has a graphic image embedded on it

I have a program that I'm writing in Android using Eclipse. It has an array of buttons (4x4).
I would like to have the buttons contain a user defined image (perhaps some filled circles).
How do I go about doing this?
Thanks
Mike
http://developer.android.com/resources/tutorials/views/hello-formstuff.html#CustomButton
Should be straight forward enough to follow.. if the image is chosen by the uesr, you will just have to change the image path on a button press or something similar

set source of ImageView dynamically android

I have an ImageView on my scene that I would like to set the source of dynamically based on user input.
Let's say I have 4 images in my drawable folder: aaa.png, bbb.png, ccc.png, and ddd.png.
When my application loads I set the image to: aaa.png
myImageView.setImageResource(R.drawable.aaa);
now I have an EditText where a user can type in bbb and I want to change the image source to be the bbb.png, or user enters ccc, change source to ccc.png etc.
how can I dynamically set the parameter in setImageResource()? I tried playing around with the Drawable object to no avail...
If you want to allow open text input, you'll either have to use raw assets to fetch them by string name (see the sidenote on that page), or else use magical Java reflection to retrieve a field of the R class by name. Alternatively, you could keep a HashMap of strings to R.drawable integer values and look it up, but then you'd have to maintain that hashmap.
If you only want it to display images that you have loaded in your drawables you can use a Spinner where the id for the item is set to be the resource for the Drawable. That would be easier on your part and easier for the user.
If you want to use reflections have a look at the code below:
R.drawable ourRID = new R.drawable();
Field photoNameField = ourRID.getClass().getField("aaa");
myImageView.setImageResource(photoNameField.getInt(ourRID));
Hope it helps.

Android:How to get back image set for a button programmatically?

I have setup background image for a button as below.
// declarations globally declared...
ImageButton sampleButton;
int sampleFirstImage = 0;
int sampleSecondImage = R.drawable.imageSecond;
......................................
......................................
sampleFirstImage = R.drawable.imageFirst;
sampleButton.setImageResource(sampleImage);
In certain cases, i want to replace this image with the another second image if the first image is set. As i need to check the condition as first image set or not for button, i need to know what image is already being set for the button. So i want to GET, image set for the button? Is there any API which gets image id set for a control?
Thanks. Appreciate if you know and can explain it to me!
If you are setting the image yourself then you could consider adding a tag (setTag) whenever you set an image source.
When you get the tag later you will know which image was last set.

Categories

Resources