How to load an imageView with the property of a bean object in android?

1

Hi, I hope I can explain myself and that you can help me, I have this class where you have a news bean property with news property. newsIconUrl that contains a URL and I need to show an image in an imageview with that url my problem is to pass that property to a global variable and then occupy it in the methods to show it in the imageview or another solution propose thanks in advance.

public class NoticiaDescripcion extends AppCompatActivity {

    TextView tv1,tv2,tv3,tv4,tv5,tv6;
    ImageView foto;
    public String imagen;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.noticia_layout);
        NewsBean noticia = (NewsBean)getIntent().getExtras().getSerializable("noticia");
        Toast.makeText(getApplicationContext(), noticia.newsIconUrl, Toast.LENGTH_LONG).show();
        tv1 = (TextView)findViewById(R.id.textView);
        tv1.setText(noticia.newsTitle);
        tv2 = (TextView)findViewById(R.id.pieFoto);
        tv2.setText(noticia.pieFoto);
        tv3 = (TextView)findViewById(R.id.lugar);
        tv3.setText(noticia.lugar);
        tv4 = (TextView)findViewById(R.id.autor);
        tv4.setText(noticia.autorNota);
        tv5 = (TextView)findViewById(R.id.seccion);
        tv5.setText(noticia.newsSeccion);
        tv6 = (TextView)findViewById(R.id.texto);
        tv6.setText(noticia.texto);
        foto = (ImageView)findViewById(R.id.imageView3);
}
}
    
asked by Bryan Antonio Smith Altobelli 24.02.2017 в 20:51
source

2 answers

1

You can use picasso

Just add it to your build.gradle file in your module

compile 'com.squareup.picasso:picasso:2.5.2'

then make use of the library as follows:

Picasso.with(NoticiaDescripcion.this).load(noticia.newsIconUrl).into(foto);

More information:

link

    
answered by 24.02.2017 в 22:18
0

To load the image you must obtain the url of the bean, as an example assuming that the method to obtain the url, accessing the property newsIconUrl is getUrl() , you would obtain the image and to load the image you can use Picasso or Glide , an example using Picasso:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.noticia_layout);
       NewsBean noticia = (NewsBean)getIntent().getExtras().getSerializable("noticia");
...
...
        //Obtiene la url del bean.
        String urlImagen = noticia.getUrl();
        //Obtiene la referencia del ImageView.
        foto = (ImageView)findViewById(R.id.imageView3);
        //Agrega la imagen al ImageView. Picasso.with(this).load(urlImagen).into(foto);
}
    
answered by 24.02.2017 в 22:15