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?