80 likes | 112 Views
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
E N D
Updated Android wants gradle line to be “implementation” rather than previous “compile” Change in gradle wants to be sync’ed again
main_activity.xml <Button android:id="@+id/btnGetImage" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="18dp" android:layout_marginTop="15dp" android:text="Get image from URL" /> <ImageView android:id="@+id/ivFromURL" android:layout_width="fill_parent" android:layout_height="match_parent" android:adjustViewBounds="false" android:scaleType="fitXY" android:src="@mipmap/ic_launcher" />
MainActivity.java package com.example.blum.myapplication;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.ImageView;import com.squareup.picasso.Picasso;public class MainActivity extends AppCompatActivity { ImageView imgFromURL; String url= "http://www.rewildthyself.com/wp-content/uploads/2015/03/poop.jpeg";@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);imgFromURL = (ImageView) findViewById(R.id.ivFromURL); Button btnGetImage = (Button) findViewById(R.id.btnGetImage); btnGetImage.setOnClickListener(new View.OnClickListener(){@Overridepublic void onClick(View v) { loadImageFromUrl(url); } //end onClick}); //end setOnClickListener} //end onCreateprivate void loadImageFromUrl(String url){// http://square.github.io/picasso/Picasso.get().load(url).into(imgFromURL); }}//end MainActivity