Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load image from URL to imageView as well as Cache

Hi i am new beginner in android. I want to insert image in imageView from URL but whenever one time it is loaded from URL in imageView then second time it should be insert without internet means it would be stored in cache as well.

like image 589
patel Avatar asked Oct 05 '15 04:10

patel


People also ask

Can ImageView be clickable?

You can make a view clickable, as a button, by adding the android:onClick attribute in the XML layout. For example, you can make an image act like a button by adding android:onClick to the ImageView .

Which attribute is used to set an image in ImageView?

2. src: src is an attribute used to set a source file or you can say image in your imageview to make your layout attractive.


2 Answers

for this you can use picasso Library You can download it from Picasso Library site simply put this jar file into libs folder. It will manage all property of Image. http://square.github.io/picasso/

String imgURL = "Your URL";
ivmage = (ImageView) findViewById(R.id.imageView1);
Picasso.with(MainActivity.this).load(imgURL).into(ivmage);
like image 65
Sam Avatar answered Sep 17 '22 15:09

Sam


You can use Picasso Library.

By Using Picasso, The Advantages are

  • Handling ImageView recycling and download cancelation in an adapter.
  • Complex image transformations with minimal memory use.
  • Automatic memory and disk caching.

To load Image from Url

Picasso.with(context).load(url).into(imageView);

Refer this link for Api : Picasso

like image 39
Rajan Kali Avatar answered Sep 17 '22 15:09

Rajan Kali