Я настраиваю imageview
, который показывает картину места, прибывающего из google places api
.... Я использую retrofit2 and pojo
.
Но я не могу получить ссылки на фотографии из pojo, который будет использовать для создания ссылки и загрузки изображения ...
Я пытался получить ссылки на фотографии из pojo, но не смог получить его ... но я успешно получил Имена из pojo
public class Recyclerview_BDA_Shop extends RecyclerView.Adapter<Recyclerview_BDA_Shop.MyViewHolder> {
private Context mContext;
private List<Result> lstResult;
public Recyclerview_BDA_Shop(Context mContext1, List<Result> lstResult) {
this.mContext = mContext1;
this.lstResult = lstResult;
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view;
LayoutInflater mInflater = LayoutInflater.from(mContext);
view = mInflater.inflate(R.layout.breakdownassitance_item, parent, false);
return new MyViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull final MyViewHolder holder, final int position) {
holder.shopName.setText(lstResult.get(position).getName());
// holder.shopOpeningHours.setText((CharSequence) lstResult.get(position).getOpeningHours());
Photo ImageReference = lstResult.get(position).getPhotos().get(1);
String photoRefrence = ImageReference.toString();
Log.d("RecyclerBDA", photoRefrence);
String link = "https://maps.googleapis.com/maps/api/place/photo?"+"maxwidth=400"+"&"+"photoreference="+photoRefrence+"&"+"key="+R.string.google_maps_key;
Picasso.get().load(link).into(holder.shopImage);
/*
holder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(mContext, Cat_Mountains_Details.class);
}
});
*/
}
@Override
public int getItemCount() {
return lstResult.size();
}
public static class MyViewHolder extends RecyclerView.ViewHolder{
TextView shopName;
TextView shopOpeningHours;
TextView shopAddress;
ImageView shopImage;
CardView cardView;
public MyViewHolder(@NonNull View itemView) {
super(itemView);
shopOpeningHours = itemView.findViewById(R.id.tv_bra_openinghours);
shopAddress = itemView.findViewById(R.id.tv_bra_address);
shopName = itemView.findViewById(R.id.tv_bra_shopName);
shopImage = itemView.findViewById(R.id.iv_bra_shopimg);
cardView = itemView.findViewById(R.id.cardview_id);
}
}
}
my logcat
2019-10-23 17:35:03.389 31208-31208/com.dionisio.automofixko E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.dionisio.automofixko, PID: 31208
java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
at java.util.ArrayList.get(ArrayList.java:437)
at com.dionisio.automofixko.adapter.Recyclerview_BDA_Shop.onBindViewHolder(Recyclerview_BDA_Shop.java:51)
at com.dionisio.automofixko.adapter.Recyclerview_BDA_Shop.onBindViewHolder(Recyclerview_BDA_Shop.java:22)
at androidx.recyclerview.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6781)
at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6823)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5752)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6019)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854)
at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230)
at androidx.recyclerview.widget.GridLayoutManager.layoutChunk(GridLayoutManager.java:557)
at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517)
at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612)
at androidx.recyclerview.widget.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:171)
at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3924)
at androidx.recyclerview.widget.RecyclerView.onMeasure(RecyclerView.java:3336)
at android.view.View.measure(View.java:22093)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
at android.view.View.measure(View.java:22093)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:733)
at com.google.android.material.appbar.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:95)
at com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1556)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:803)
at android.view.View.measure(View.java:22093)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
at android.view.View.measure(View.java:22093)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
at android.view.View.measure(View.java:22093)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:22093)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
at android.view.View.measure(View.java:22093)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:735)
at android.view.View.measure(View.java:22093)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2433)
2019-10-23 17:35:03.391 31208-31208/com.dionisio.automofixko E/AndroidRuntime: at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1515)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1772)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1403)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6804)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:169)
at android.app.ActivityThread.main(ActivityThread.java:6521)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
результат POJO
public class Result {
@SerializedName("geometry")
@Expose
private Geometry geometry;
@SerializedName("photo")
@Expose
private Photo photo;
@SerializedName("icon")
@Expose
private String icon;
@SerializedName("id")
@Expose
private String id;
@SerializedName("name")
@Expose
private String name;
@SerializedName("opening_hours")
@Expose
private OpeningHours openingHours;
@SerializedName("photos")
@Expose
private List<Photo> photos = new ArrayList<Photo>();
@SerializedName("place_id")
@Expose
private String placeId;
@SerializedName("rating")
@Expose
private Double rating;
@SerializedName("reference")
@Expose
private String reference;
@SerializedName("scope")
@Expose
private String scope;
@SerializedName("types")
@Expose
private List<String> types = new ArrayList<String>();
@SerializedName("vicinity")
@Expose
private String vicinity;
@SerializedName("price_level")
@Expose
private Integer priceLevel;
/**
*
* @return
* The geometry
*/
public Geometry getGeometry() {
return geometry;
}
/**
*
* @param geometry
* The geometry
*/
public void setGeometry(Geometry geometry) {
this.geometry = geometry;
}
/**
*
* @return
* The icon
*/
public String getIcon() {
return icon;
}
/**
*
* @param icon
* The icon
*/
public void setIcon(String icon) {
this.icon = icon;
}
/**
*
* @return
* The id
*/
public String getId() {
return id;
}
/**
*
* @param id
* The id
*/
public void setId(String id) {
this.id = id;
}
/**
*
* @return
* The name
*/
public String getName() {
return name;
}
/**
*
* @param name
* The name
*/
public void setName(String name) {
this.name = name;
}
/**
*
* @return
* The openingHours
*/
public OpeningHours getOpeningHours() {
return openingHours;
}
/**
*
* @param openingHours
* The opening_hours
*/
public void setOpeningHours(OpeningHours openingHours) {
this.openingHours = openingHours;
}
/**
*
* @return
* The photos
*/
public List<Photo> getPhotos() {
return photos;
}
/**
*
* @param photos
* The photos
*/
public void setPhotos(List<Photo> photos) {
this.photos = photos;
}
/**
*
* @return
* The placeId
*/
public String getPlaceId() {
return placeId;
}
/**
*
* @param placeId
* The place_id
*/
public void setPlaceId(String placeId) {
this.placeId = placeId;
}
/**
*
* @return
* The rating
*/
public Double getRating() {
return rating;
}
/**
*
* @param rating
* The rating
*/
public void setRating(Double rating) {
this.rating = rating;
}
/**
*
* @return
* The reference
*/
public String getReference() {
return reference;
}
/**
*
* @param reference
* The reference
*/
public void setReference(String reference) {
this.reference = reference;
}
/**
*
* @return
* The scope
*/
public String getScope() {
return scope;
}
/**
*
* @param scope
* The scope
*/
public void setScope(String scope) {
this.scope = scope;
}
/**
*
* @return
* The types
*/
public List<String> getTypes() {
return types;
}
/**
*
* @param types
* The types
*/
public void setTypes(List<String> types) {
this.types = types;
}
/**
*
* @return
* The vicinity
*/
public String getVicinity() {
return vicinity;
}
/**
*
* @param vicinity
* The vicinity
*/
public void setVicinity(String vicinity) {
this.vicinity = vicinity;
}
/**
*
* @return
* The priceLevel
*/
public Integer getPriceLevel() {
return priceLevel;
}
/**
*
* @param priceLevel
* The price_level
*/
public void setPriceLevel(Integer priceLevel) {
this.priceLevel = priceLevel;
}
public Photo getPhoto() {
return photo;
}
public void setPhoto(Photo photo) {
this.photo = photo;
}
}
фото POJO
public class Photo {
@SerializedName("height")
@Expose
private Integer height;
@SerializedName("html_attributions")
@Expose
private List<String> htmlAttributions = new ArrayList<String>();
@SerializedName("photo_reference")
@Expose
private String photoReference;
@SerializedName("width")
@Expose
private Integer width;
/**
*
* @return
* The height
*/
public Integer getHeight() {
return height;
}
/**
*
* @param height
* The height
*/
public void setHeight(Integer height) {
this.height = height;
}
/**
*
* @return
* The htmlAttributions
*/
public List<String> getHtmlAttributions() {
return htmlAttributions;
}
/**
*
* @param htmlAttributions
* The html_attributions
*/
public void setHtmlAttributions(List<String> htmlAttributions) {
this.htmlAttributions = htmlAttributions;
}
/**
*
* @return
* The photoReference
*/
public String getPhotoReference() {
return photoReference;
}
/**
*
* @param photoReference
* The photo_reference
*/
public void setPhotoReference(String photoReference) {
this.photoReference = photoReference;
}
/**
*
* @return
* The width
*/
public Integer getWidth() {
return width;
}
/**
*
* @param width
* The width
*/
public void setWidth(Integer width) {
this.width = width;
}
}