【问题标题】:My image is not loading in image view in json volley method我的图像未在 json volley 方法中的图像视图中加载
【发布时间】:2018-02-17 11:56:06
【问题描述】:

我的适配器 file.java 我使用JSON volley 方法。 Image is not load the image view 这个问题怎么解决?

杰森图片格式;

"image":[  
   "151660038947843.png",
   "151660038916249.png"
],

MyAdapter.java

public void onBindViewHolder(MyViewHolder holder, int position) 
{
    final Hostel hostel = hostelList.get(position);

    holder.name.setText(hostel.getName());
    holder.mobile1.setText( hostel.getMobile1() );
    holder.mobile2.setText( hostel.getMobile2() );
    holder.address.setText( hostel.getAddress() );
    holder.place.setText( hostel.getPlace() );

    Glide.with(mContext).load(hostel.getImage()).into(holder.image);
}

MyActivity.java

if(!(1 <= distance)){
    jsonName = jsonObject.getString("pname");                            
    jsonMobile1 = jsonObject.getString("price");
    jsonMobile2=jsonObject.getString( "discount" );
    jsonAddress=jsonObject.getString("pdescription");
    jsonArea=jsonObject.getString( "area" );                             
    JSONArray jsonImage = jsonObject.getJSONArray("image");
    jsonPhoto = jsonImage.getString(0);
    Hostel hostel=new Hostel(jsonPhoto, jsonName,jsonMobile1,jsonMobile2,jsonAddress,jsonArea );
    hostelList.add(hostel);
}

【问题讨论】:

  • hostel.getImage()。请告诉价值。现在还不清楚你给 Glide 哪个 url。此外,还不清楚是否有图像文件。他们在哪里?在设备上?它们必须下载吗?你什么都没说。您只显示了一些图片名称。
  • 我正在上传 json file.jpg 格式的图片
  • 应该有完整的url来加载图片而不是图片名称。
  • 图像路径不能描述图像的完整主页,您应该提供完整路径@NmSankar
  • 如何提供完整路径。任何示例

标签: android json imageview android-volley


【解决方案1】:

您需要在 json 响应中包含图像的 url 或路径。您不能将&lt;ImageName&gt;.png 作为输入。

【讨论】:

  • 放置此网址的位置
  • 您的 hostel.getImage() 应该返回图像的 url 或路径。在形成 hostel 对象时,您应该像 hostel.setImage(" ") 一样继续
猜你喜欢
  • 2020-03-18
  • 1970-01-01
  • 1970-01-01
  • 2017-12-31
  • 2015-09-20
  • 1970-01-01
  • 2016-07-27
  • 1970-01-01
  • 2016-11-23
相关资源
最近更新 更多