2012-02-21 125 views
0

我已成功解析了我的json图像并将响应显示为图像,但是我一次只能显示一个图像。将这些json图像显示为列表视图

enter image description here

如何显示使用该代码的这些图像列表视图。

在发布这个问题之前,我也期待这个解决方案。我想使用下面的代码将这些图像显示为listview以及其他json值。

protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

    JSONParser prop = new JSONParser(); 
    JSONObject json = prop.getJSONFromUrl(url); 
    try{ 
    properties = json.getJSONArray(TAG_PROPERTY); 
    for (int i = 0; i < properties.length(); i++) { 
     JSONObject c = properties.getJSONObject(i); 
     String photoThumbnailUrl = c.getString(TAG_PHOTOS);    

    // load image view control 
    imgView = (ImageView) findViewById(R.id.imgView); 

    // grab image to display 
    try { 
     imgView.setImageDrawable(grabImageFromUrl(photoThumbnailUrl)); 


    } catch (Exception e) { 
     txtUrl.setText("Error: image not grabed"); 
    } 
    } 
    }catch (Exception ex) { 
    txtUrl.setText("Error: Properties not recieved"); 
    } 
} 
private Drawable grabImageFromUrl(String photoThumbnailUrl) { 
    System.out.println(photoThumbnailUrl); 
    // TODO Auto-generated method stub 
    return null; 
} 
//from here only one image is displayed.... 
//start the listview here 

    public View getView(int position, View convertView, ViewGroup parent) { 
     System.out.println("ok"); 
     // TODO Auto-generated method stub 
     ViewHolder holder; 
     if (convertView == null) { 
      //convertView = inflater.inflate(R.layout.list_items, null); 
      holder = new ViewHolder(); 
      holder.identifier= (TextView) convertView 
        .findViewById(R.id.identifier); 
      holder.price = (TextView) convertView.findViewById(R.id.price); 
      holder.address = (TextView) convertView.findViewById(R.id.address); 
      holder.photoThumbnailUrl = (ImageView) convertView 
        .findViewById(R.id.imgView); 
      convertView.setTag(holder); 
      System.out.println("identifier"); 
     } else { 
      holder = (ViewHolder) convertView.getTag(); 
     } 
     return convertView; 
} 
    class ViewHolder{ 
     public TextView identifier; 
     public TextView price; 
     public TextView address; 
     public ImageView photoThumbnailUrl; 

    } 
    } 

非常感谢

回答

2

我想你应该创建一个XML自定义列表视图项,并使用SimpleAdapter来填充每一行与JSON项目。一段时间回来用this文章来帮助我,我希望它也能帮助你。

0

对于列表视图,你需要下载每个行的新内容。

这可能会很难做到正确。我创建了这里帮手: https://github.com/mufumbo/android-helper/blob/master/src/com/mufumbo/android/helper/ThumbLoader.java

使用示例:

让您ViewHolder实现{@link ThumbLoader.ThumbEvent},然后填充ViewHolder时:

ThumbLoader thumbLoaderInstance;

公共视图getView(INT位置,查看convertView,父的ViewGroup){

....

thumbLoaderInstance.pushEvent(支架,TRUE);
....

}