2012-02-21 2 views
0

json 이미지를 성공적으로 파싱하여 이미지로 응답을 표시했지만 한 번에 하나의 이미지 만 표시 할 수 있습니다.이 json 이미지를 목록보기로 표시

enter image description here

어떻게이 코드를 사용하여 목록보기 이러한 이미지를 표시 할 수 있습니다.

이 질문을 게시하기 전에이 솔루션을 찾고 있습니다. 아래 코드를 사용하여 이러한 이미지를 다른 json 값과 함께 listview로 표시하려고합니다.

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로 정의 목록보기 항목을 작성하고 JSON 항목과 각 행을 채우기 위해 SimpleAdapter를 사용한다고 생각합니다. 잠시 후, 나를 도울 수있는 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, 뷰 그룹의 부모) {

....

thumbLoaderInstance.pushEvent (홀더, TRUE);
....

}

관련 문제