【问题标题】:how do i get imagedownloadservice to work with multilist component in codenameone?如何让 imagedownloadservice 与 codenameone 中的多列表组件一起使用?
【发布时间】:2013-03-15 21:18:20
【问题描述】:

我在 GUI Designer 中创建了一个多列表。我将模型设置如下

   @Override
protected boolean initListModelMultiIssueList(List cmp) {
    fetchIssues(cmp);
    if (issueVector != null ) {
    cmp.setModel(new DefaultListModel(issueVector));
    System.out.println(cmp);
    }
    return true;
}
void fetchIssues( List c){
    //fetch issues based on the searchquery hash
    //first thing is to create the query from the hash
    System.out.println("Starting to fetch results");
    try{
        java.util.List<ServiceRequest> serviceRequests = ServiceRequest.getServiceRequests(formQuery(searchQuery),true);
        //we need to now populate the issueVector
        //with the data
        System.out.println(serviceRequests.toString());
        if (issueVector != null ) {
            issueVector.clear();
        } else {
            issueVector = new Vector();
        } 
        int index = 0;
        for (ServiceRequest serviceRequest : serviceRequests) {
                Hashtable hIssue = new Hashtable();
                hIssue.put("id",serviceRequest.getHref());
                //System.out.println(hIssue); 

                ImageDownloadService.createImageToStorage(serviceRequest.getRequestPictureURL().toString(),
                        c, index, "icon", 
                        "service-icon-"+ index ,null);
                //hIssue.put("icon", serviceRequest.getRequestPictureURL().toString());
                //System.out.println(hIssue);
                //reverse geocode the location
                Double x = new Double(0.0);
                x=new Double(serviceRequest.getRequestLocationLatitude());
                Double y = new Double(serviceRequest.getRequestLocationLongitude());
                String location=reverseGeocode(x, y);
                hIssue.put("location", location);
                //System.out.println(hIssue);
                Service service = serviceRequest.loadService();
                hIssue.put("service", serviceRequest.loadService().getName().toString());
                hIssue.put("reportedOn",serviceRequest.getCreatedAt().toString());
                //System.out.println("Final hIssue" + hIssue.toString());
                issueVector.add(hIssue);
                index=index+1;
                System.out.println(issueVector);
        }

    }catch (Exception e){
        System.out.println("Error loading search results");
        System.out.println(e);
    }
}

多列表 GUI 设计中的图标已设置为适当的属性。 ImageDownloadService 确实下载了图像文件,但它没有按预期显示在列表中。我做错了什么?

【问题讨论】:

    标签: codenameone


    【解决方案1】:

    可能是在条目可用之前下载了图像。虽然很难用代码来判断并且没有对症状的明确解释。

    您需要首先创建模型并将其设置到列表中(最好使用空白占位符图像,这样列表就不会“跳跃”)。那么就需要遍历列表并调用图片下载服务,否则可能会在数据还没到列表之前就返回而失败!如果图像已经在缓存中,则可能会发生这种情况,因此在这种情况下它很可能会快速失败。

    【讨论】:

    • 好的。如果我理解正确,我应该创建模型并设置到列表中。所以在我的代码中,我应该在设置模型之后而不是之前调用 fetchIssues()。我会试试的。
    • 试过但不起作用。理解是,首先构建列表并设置为模型和显示。然后再次循环列表并使用 imagedownloadservice 进行更新。要求图标已经在列表中定义了一些占位符值,imagedownloadservice 将替换该值。我会尝试清楚,看看我是否可以实现。
    • 究竟是什么不起作用?你是在调试器中运行的吗?你有例外吗?您是否查看过使用此功能的 facebook 演示等演示?
    • 我可以看到图像已下载,但未显示在列表中。我将再次查看 Facebook 演示。
    猜你喜欢
    • 1970-01-01
    • 2022-09-30
    • 2022-06-15
    • 2018-02-17
    • 2014-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多