This is the code i use, the library is imported from the jar, the image link works fine and i even added the internet permissions in the AndroidManifest.xml. The problem is that when i start the app it opens and closes without showing anything.
package my.pkg.name;
import com.squareup.picasso.*;
import android.R.id.*;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
public class MainActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.id.immagine);
ImageView targetImageView = (ImageView) findViewById(R.id.immagine);
String internetUrl = "http://i.imgur.com/DvpvklR.png";
Picasso
.with(this)
.load(internetUrl)
.into(targetImageView);
}
}
And this is the layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="just a string"
/>
<ImageView
android:id="@+id/immagine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="213"
/>
</LinearLayout>
Thank you
setContentView(R.id.immagine);
is wrong. Usually you put R.layout.something
into setContentView
.
Also, remember, except that Layout
as @eriuzo said, that could be due to Activity
:
public class MainActivity extends Activity
For these situations, you should check the logcats if something is wrong.but, You can use that with AppCompatActivity
that should solve the problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.