I just start using Picasso to download, store and retrieve images, but I gut stuck in the first step. I write the simplest code ever but it is not loading anything! here is the code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b = (Button) findViewById(R.id.button1);
final ImageView imageView = (ImageView) findViewById(R.id.imageView1);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Picasso.with(getApplicationContext()).load("http://www.farsnews.com/shares/img/PLogo.jpg").into(imageView);
}
});
}
and the layout is :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:layout_gravity="center"
android:gravity="center">
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="@drawable/ic_launcher"
tools:ignore="ContentDescription"/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="26dp"
android:text="Button" />
so, why it is not working?
And is it really a good choice to use Picasso lib for download, store and retrieve images?
try removing this line :
android:src="@drawable/ic_launcher"
Edit : also forgetting Internet Permission will cause picasso to fail!
<uses-permission android:name="android.permission.INTERNET" />