i developing an application, in that i configure html data . But the background image for data is not effected means the image path is not getting.
i placed my image :res/drawable-hdpi folder.
and i am using the following logic:
strBody += "<tr><td background='../res/drawable-hdpi/msgblue_box.png' style='word-break:break-all;width:50%;'>" + dslist.get(i).getBody()+"<br>"+ dslist.get(i).getDateformat()+ "</td><td style='width:50%'></td></tr>";
So, please guide me how solve this.
you need to use the getResources.getDrawable to get image in your code
ImageView img=new ImageView(this);
Drawable im= getResources().getDrawable(R.drawable.name);
img.setImageDrawable(im);
strBody += "<tr><td background="+img+ "style='word-break:break-all;width:50%;'>" + dslist.get(i).getBody()+"<br>"+ dslist.get(i).getDateformat()+ "</td><td style='width:50%'></td></tr>";
Related
Trying to change the profile image on the web view.
But when trying the updated image showing a crashed image.
webView.loadUrl("javascript: (function() {document.getElementById('SelectedImage').src='"+profilePath+"';}) ();");
If profilePath is a Uri object, then you need to get the absolute path from the object. Use File f = new File(profilePath.toString());
is it possible to get the src Value of an ImageView as URI?
Help would be great
No. By the time the ImageView has the image, the source of that image is long gone.
If you know what image it is in your drawable, you can do something like this.
String path = Uri.parse("android.resource://my.package.name/" + R.drawable.myimage).toString();
More info - https://stackoverflow.com/a/28505621/2197529
Ok, after searching and browsing over the internet, I just didn't get what I was looking for. I have a database with a field for "Path", where my images file names are listed.
**Table1:**
PATH ID
imgRice.jpg 1
imgMango.jpg 2
imgBanana.jpg 3
Now I want my imageView to change picture accordingly from my query:
"Select Path from table1 where ID = 1";
I will declare a String, like String queryResultString to handle the result (ex.imgRice.jpg).
I want a code that looks like imgView.image="drawable/" + queryResultString
Any help is appreciated. Thanks guys!
Thanks for the comments and suggestions guys, highly appreciated.
But I've got a simple yet tricky turnaround for my problem.
First, it is IMPOSSIBLE to rip the Drawable path because it is compressed when published to .apk file.
Second, to make it possible, you need to use id for every file in your drawable.
Third, it is much better to add files(images) to asset folder(\app\src\main\assets).
Lastly, follow these simple codes:
//code to initiate the object ImageView...
ImageView myImage = (ImageView) findViewById(R.id.pic);//pic is the id of ImageView in my xml file...
try
{
// now, get the input stream
InputStream input= getAssets().open(c.getString(c.getColumnIndex("image")));//image is the name of field in my db which holds the path (ex. rice.jpg)...
// initiate image as drawable
Drawable draw = Drawable.createFromStream(input, null);
// set image to ImageView
myImage.setImageDrawable(draw);
}
catch(IOException ex)
{
return;
}
Enjoy Coding! ^_^
Is there any good way to use frame by frame animation AnimationDrawable using UIL library. AnimationDrawable accept only BitmpaDrawable . Is there any way to convert quickly to bitmaps my images or any maybe there is method like imageLoader.getBitmap, I haven't find anything like that.
Please help , I would be very grateful for any help .
Edit I have my images in assets folder. Maybe there any way to get bitmap from cache or something else . I need open new activity , maybe several times . I need to show animation from files , but if I use decode it takes a lot of time to decode them . Please suggest something
If your images are resources you can use this for obtain Bitmap:
Bitmap icon = BitmapFactory.decodeResource(context.getResources(),
R.drawable.icon_resource);
else, if you want donwload the image you can use this:
String name = c.getString(url);
URL urlAux = new URL(name);
ImageView prueba = (ImageView)v.findViewById(R.id.iv_prueba);
if (prueba != null) {
Bitmap bitmap =
BitmapFactory.decodeStream(urlAux.openConnection().getInputStream());
prueba.setImageBitmap(bitmap);
}
Hope it helps you.
I was trying to set the TabBar Icons dynamically by first downloading them from the server and then setting them as:
String path = context.getFilesDir().getAbsolutePath() + "/HDPI/" +"dial.png";
File imgFile = new File(path);
Drawable icon = Drawable.createFromPath(imgFile.getAbsolutePath());
dialer.setIndicator(getString(R.string.Keypad), icon).setContent(dialerIntent);
The Output that i get doing so is as followed :
I get the correct image but the size of the image gets reduced.
I don't understand why its so. I would be grateful if anyone can figure out the mistake that I make or could suggest me some new approach to do so.
Thanks.