簡體   English   中英

將這些json圖片顯示為listview

[英]Display these json images as listview

我已經成功解析了json圖像並將響應顯示為image,但是一次只能顯示一個圖像。

在此處輸入圖片說明

如何使用此代碼將這些圖像顯示為列表視圖。

在發布此問題之前,我還期待着這種解決方案。 我想使用以下代碼將這些圖像與其他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;

    }
    }

非常感謝

我認為您應該使用XML創建一個自定義listview項,並使用SimpleAdapter用JSON項填充每一行。 前陣子使用文章來幫助我,我希望它可以幫助你。

對於列表視圖,您需要為每一行下載新內容。

要正確完成此操作可能很棘手。 我在這里創建了一個幫助器: https//github.com/mufumbo/android-helper/blob/master/src/com/mufumbo/android/helper/ThumbLoader.java

用法示例:

使您的ViewHolder實現{@link ThumbLoader.ThumbEvent},然后在填充ViewHolder時:

ThumbLoader thumbLoaderInstance;

public View getView(int position,View convertView,ViewGroup parent){

....

thumbLoaderInstance.pushEvent(holder,true);
....

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM