I make an application that receives JSON from the server. His appearance is as follows:

[ { "id": 1, "typeOfOrganization": "Администрации", "created_at": 1462233600000, "url": "https://...../images/icon.png" }, { "id": 2, "typeOfOrganization": "архив", "created_at": 1462233600000, "url": "https://.../images/icon.png" } ] 

Where in the url is stored the absolute path to the picture. I get this JSON successfully:

 private class OrgMeTask extends AsyncTask<Void, Void, OrgDTO[]> { @Override protected OrgDTO[] doInBackground(Void... params) { RestTemplate template = new RestTemplate(); template.getMessageConverters().add(new MappingJackson2HttpMessageConverter()); OrgDTO[] result = template.getForObject(Constans.URL.GET_PUBLIC_ORG_ITEM, OrgDTO[].class); return result; } @Override protected void onPostExecute(OrgDTO[] orgDTO) { List<OrgDTO> data = new ArrayList<>(); for (int i = 0; i < orgDTO.length; i++) { data.add(orgDTO[i]); } adapter.setData(data); } } 

In the data sheet come the data:
The markup is as follows:

  <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="14dp" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/title" android:textSize="8pt" android:textColor="@color/colorBlack" android:paddingBottom="5dp" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TEST"/> </LinearLayout> </LinearLayout> </android.support.v7.widget.CardView> 

The corresponding setters and getters are created in the dto class:

 package com.spravka.dto; import android.graphics.Bitmap; import java.util.Date; public class OrgDTO { public OrgDTO() { } private int id; private String typeOfOrganization; private Date created_at; private String url; public Bitmap getImage() { return image; } public void setImage(Bitmap image) { this.image = image; } private Bitmap image; public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } } 

In the adapter prescribed:

  public void onBindViewHolder(OrgViewHolder holder, int position) { OrgDTO item = data.get(position); holder.title.setText(item.getTitle()); holder.imageView.setImageBitmap(item.getImage()); } public static class OrgViewHolder extends RecyclerView.ViewHolder { CardView cardView; TextView title; ImageView imageView; public OrgViewHolder(View itemView) { super(itemView); cardView = (CardView) itemView.findViewById(R.id.cardView); title = (TextView) itemView.findViewById(R.id.title); imageView = (ImageView) imageView.findViewById(R.id.imageView); } } 

Tell me how and where now I get a Bitmap from the link and put it in the ImageView?

    2 answers 2

    Lord, why so much text when all your question boils down to one thing: “how can I display a picture in ImageView from the url in the android?”. And the decision is googled in 5 minutes. Here are the most popular libraries that were created specifically for this task (as well as caching, some image transformations and other popular actions): Picasso , Fresco , Glide , Universal Image Loader .

    The easiest option is probably Picaso:

     Picasso.with(holder.imageView.getContext()) .load(item.getUrl()) .into(holder.imageView); 
    • I understand this perfectly well, that the question boils down to one, but I still ask how and where to get it from the data url - R.Skidan
    • one
      @ R.Skidan, no, you do not ask. - Vladyslav Matviienko
    • @ R.Skidan do not ask, and it seems like you even do it yourself: OrgDTO item = data.get(position); - xkor

    Well, first, do it all through RecyclerView .

    Register your own RecyclerViewAdapter (there are lessons in the internet).

    After that, get links from the class and paste with Picasso .

    Recently JSON with parsils pictures: an example on github

    • If you look closely at the adapter code in question, then, it seems, it is very clear that RecycleView is used as it is - pavlofff