简体   繁体   English

在Android的ExpandableListView中的ImageView处从webUrl加载图像

[英]Load image from webUrl at ImageView in ExpandableListView in android

In my project i am using google webService in which i am quering different query like-- hospital, cinema hall, resort etc. and get result in json format . 在我的项目中,我使用的是google webService,在其中我查询了不同的查询,例如-医院,电影院,度假村等,并以json格式获取结果。 From json i get so many data like Name, lat, lng, imageUrl, Web url in respective query. 从json中,我在各自的查询中获得了很多数据,例如Name,lat,lng,imageUrl,Web url。 And i am manupulating these data and showing it in my Expandable listView. 我正在处理这些数据,并将其显示在我的Expandable listView中。 I am able to do show all data but when i am loading image on ImageView it is showing some mismatch. 我能够显示所有数据,但是当我在ImageView上加载图像时,它显示出一些不匹配。 For loading image, I am using ImageLoader, FileCache, MemoryCache and Utils java class. 为了加载图像,我使用了ImageLoader,FileCache,MemoryCache和Utils java类。 Basically question is i have http web url for image and now i want to show it on my ImageView at Expandable listView, and i am not properly perform it. 基本上的问题是我有图像的http Web URL,现在我想在Expandable listView的ImageView上显示它,而我不能正确执行它。 Please any buddy help. 请任何伙伴的帮助。

Actually you have not posted any code so it is difficult to tell you the exact problem, but this link will help you, here i am fetching data into listview using json, use as you need 实际上您尚未发布任何代码,因此很难告诉您确切的问题,但是此链接将为您提供帮助,在这里,我正在使用json将数据提取到listview中,并根据需要使用

I want to let user add multiple items by action sequence 我想让用户按操作顺序添加多个项目

Some Code:- 一些代码:

JSONArray jsonArray = json.getJSONArray(KEY_CATEGORY);

for(int i=0;i < jsonArray.length();i++){                        
    HashMap<String, String> map = new HashMap<String, String>();
    JSONObject jsonObject = jsonArray.getJSONObject(i);                     

    map.put("id",  String.valueOf(i));
    map.put(KEY_TITLE, jsonObject.getString(KEY_TITLE));
    map.put(KEY_DESCRIPTION, jsonObject.getString(KEY_DESCRIPTION));
    map.put(KEY_COST, jsonObject.getString(KEY_COST));
    map.put(KEY_THUMB_URL, jsonObject.getString(KEY_THUMB_URL));
    itemsList.add(map);
} 

Tikam done, try to use this class, Tikam做完了,尝试使用此类,

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;



    /**
     * 
     * @author JSR
     *
     */

 public class StreamUtils {

/**
 * A helper method to convert an InputStream into a String
 * @param inputStream
 * @return the String or a blank string if the IS was null
 * @throws IOException
 */
public static String convertToString(InputStream inputStream) throws IOException {
    if (inputStream != null) {
        Writer writer = new StringWriter();

        char[] buffer = new char[1024];
        try {
            Reader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 1024);
            int n;
            while ((n = reader.read(buffer)) != -1) {
                writer.write(buffer, 0, n);
            }
        } finally {
            inputStream.close();
        }
        return writer.toString();
    } else {
        return "";
    }
}
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM