0

我尝试在下面分析此 json 表,源代码探针将显示文本,但我尝试从 json 表中的 url 加载的图像但图像不显示仅空白屏幕显示此图像http://imgur.com/hsYqtyd

{
    "worldpopulation": 
    [
        {
            "rank":1,
            "name": "BREAKFAST",
            "url": "http://www.androidbegin.com/tutorial/flag/china.png"
        },
        {   
            "rank":2,
            "name": "LUNCH ",
            "url": "http://www.androidbegin.com/tutorial/flag/china.png"
        },
        {  
            "rank":3,
            "name": "SUPPER",
            "url": "http://www.androidbegin.com/tutorial/flag/china.png"
        }
    ]
}

public void parseJSONData(){
    //CategoryAPI = Utils.CategoryAPI+"?accesskey="+Utils.AccessKey;    
    CategoryAPI = Utils.CategoryAPI;        
    clearData();
    try {            
        HttpClient client = new DefaultHttpClient();
        HttpConnectionParams.setConnectionTimeout(client.getParams(), 15000);
        HttpConnectionParams.setSoTimeout(client.getParams(), 15000);
        HttpUriRequest request = new HttpGet(CategoryAPI);
        HttpResponse response = client.execute(request);
        InputStream atomInputStream = response.getEntity().getContent();
        BufferedReader in = new BufferedReader(new 
        InputStreamReader(atomInputStream));

        String line;
        String str = "";
        while ((line = in.readLine()) != null) {
            str += line;
        }       

        JSONObject json = new JSONObject(str);
        JSONArray data = json.getJSONArray("worldpopulation");

        for (int i = 0; i < data.length(); i++) {
            JSONObject object = data.getJSONObject(i);                 
            //JSONObject category = object.getJSONObject("Category");                    
            Category_ID.add(Long.parseLong(object.getString("rank")));
            Category_name.add(object.getString("name"));
            Category_image.add(object.getString("url"));
            Log.d("Category name", Category_name.get(i));

        }                          
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        IOConnect = 1;
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }   
}

class CategoryListAdapter extends BaseAdapter {
    private Activity activity;
    private ImageLoader imageLoader;

    public CategoryListAdapter(Activity act) {
        this.activity = act;
        imageLoader = new ImageLoader(act);
    }

    public int getCount() {
        // TODO Auto-generated method stub
        return CategoryList.Category_ID.size();
    }

    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        ViewHolder holder;

        if(convertView == null) {
            LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.category_list_item, null);
            holder = new ViewHolder();

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }


        holder.txtText = (TextView) convertView.findViewById(R.id.txtText);
        holder.imgThumb = (ImageView) 
        convertView.findViewById(R.id.imgThumb);

        holder.txtText.setText(CategoryList.Category_name.get(position));

        imageLoader.DisplayImage(Utils.AdminPageURL+CategoryList.Category_image.get(position), activity, holder.imgThumb);

        return convertView;
    }

    static class ViewHolder {
        TextView txtText;
        ImageView imgThumb;
    }        
}
4

2 回答 2

0

您必须下载该图像并在图像视图中显示

于 2013-07-15T12:25:52.857 回答
0

您没有发布代码,imageLoader.DisplayImage()但我认为这是您下载图像并将其设置到 ImageView 的地方。

从您附加的图像中,我会说您需要invalidate()在通过 setImage() 或 setBackground() 将照片添加到 ImageView 后调用它。

于 2013-07-15T12:46:00.850 回答