2012-02-21 46 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);
....

}