Picasso Revisted Updated Android wants gradle line to
- Slides: 8
Picasso Revisted
Updated Android wants gradle line to be “implementation” rather than previous “compile” Change in gradle wants to be sync’ed again
Choose to Sync
Picasso site/documentation
Add Internet permission to manifest
main_activity. xml <Button android: id="@+id/btn. Get. Image" android: layout_width="fill_parent" android: layout_height="wrap_content" android: layout_margin. Left="18 dp" android: layout_margin. Top="15 dp" android: text="Get image from URL" /> <Image. View android: id="@+id/iv. From. URL" android: layout_width="fill_parent" android: layout_height="match_parent" android: adjust. View. Bounds="false" android: scale. Type="fit. XY" android: src="@mipmap/ic_launcher" />
Main. Activity. java package com. example. blum. myapplication; import import android. support. v 7. app. App. Compat. Activity; android. os. Bundle; android. view. View; android. widget. Button; android. widget. Image. View; import com. squareup. picasso. Picasso; public class Main. Activity extends App. Compat. Activity { Image. View img. From. URL; String url= "http: //www. rewildthyself. com/wpcontent/uploads/2015/03/poop. jpeg"; @Override protected void on. Create(Bundle saved. Instance. State) { super. on. Create(saved. Instance. State); set. Content. View(R. layout. activity_main); img. From. URL = (Image. View) find. View. By. Id(R. id. iv. From. URL); Button btn. Get. Image = (Button) find. View. By. Id(R. id. btn. Get. Image); btn. Get. Image. set. On. Click. Listener(new View. On. Click. Listener(){ @Override public void on. Click(View v) { load. Image. From. Url(url); } //end on. Click }); //end set. On. Click. Listener } //end on. Create private void load. Image. From. Url(String url){ // http: //square. github. io/picasso/ Picasso. get(). load(url). into(img. From. URL); } }//end Main. Activity
Before and after clicking button