Online image in Adapter

Asked

Viewed 37 times

0

I have an Adapter in my App, and I would like to take pictures of my server to put in it instead of a photo saved at the root, I’ve tried several ways, I’ve tried even using the Picasso API but the most I could was 1 photo for toads.

Adapter:

public CursoAdapter(Context context,ArrayList<curso>  elementos)  {

    super(context,R.layout.linha,  elementos);
    this.context=context;
    this.elementos=  elementos;
}

@Override
public View getView(int position, View convertView, ViewGroup parent)
{

    Context contexts = parent.getContext();
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(R.layout.linha, parent, false);
    TextView nomeCurso = (TextView) rowView.findViewById(R.id.nome);
    TextView progresso = (TextView) rowView.findViewById(R.id.endereco);
    ImageView imagem = (ImageView) rowView.findViewById(R.id.imagem);
    nomeCurso.setText(elementos.get(position).getNome());
    progresso.setText(elementos.get(position).getEndereco());
    imagem.setImageResource(elementos.get(position).getImagem());
    return rowView;
}

My XML:

    <ImageView
    android:id="@+id/imagem"
    android:layout_width="64dp"
    android:layout_height="69dp"
    android:layout_margin="5dp"
    android:scaleType="fitXY"
    android:src="@drawable/e1" />

<LinearLayout
    android:layout_width="304dp"
    android:layout_height="73dp"
    android:layout_gravity="right"
    android:orientation="vertical">

    <TextView
        android:id="@+id/nome"
        android:layout_width="227dp"
        android:layout_height="38dp"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="10dp"
        android:text="Nomedascola"
        android:textAppearance="@style/Base.TextAppearance.AppCompat.SearchResult.Title"
        android:textSize="15dp" />

    <TextView
        android:id="@+id/endereco"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:text="Endereço"
        android:textAppearance="@style/Base.TextAppearance.AppCompat.Small" />
</LinearLayout>

Adding items:

 curso e = new curso(array2[0],"Progresso: 0%", drawable.e1);
 escolas.add(e);
 return escolas;

1 answer

1


I solved using this scheme: (In my Adapter)

    Bitmap bitmap = null;
    try {
        //.makeText(contexts, mag, Toast.LENGTH_SHORT).show();
        bitmap = BitmapFactory.decodeStream((InputStream) new URL(Minha_URL).getContent());
        imagem.setImageBitmap(bitmap);
    } catch (IOException e) {
        e.printStackTrace();
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.