【问题标题】:List renderer issue in codenameone列出代号中的渲染器问题
【发布时间】:2016-01-12 12:36:45
【问题描述】:

我使用了列表渲染器,一切正常。然后我保留了一个提取的最后点击项,如下所示: 渲染器中有 3 个按钮。 button1 可以正常工作,但是 button2 和 button3 在某些情况下可以工作,而在其他情况下不能工作?为什么? 如果我从下面的代码中删除if (lastClickedButton != null),它会为之前在其他列表项中工作的同一个按钮提供NullPointerException

我的代码:

@Override
    protected boolean initListModelListEmergencyList(List cmp) {
        cmp.setModel(new com.codename1.ui.list.DefaultListModel(emergencyPoliceArray));
        cmp.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                for (int i = 0; i < emergencyPoliceArray.size(); i++) {
                    if (cmp.getSelectedItem() == emergencyPoliceArray.get(i)) {

                        lastClickedButton = ((GenericListCellRenderer) cmp.getRenderer()).extractLastClickedComponent();
                        if (lastClickedButton != null) {
                            System.out.println("Phn no: " + lastClickedButton.getText());
                    }
                }
            }
        }
    }
    );

return true;
    }

我的连接:

private void showEmergencyDetails() {
        JSONParser p = new JSONParser();
        Hashtable<String, Object> test;
        try {
            test = p.parse(new InputStreamReader(is));
            Vector emergencyVector = (Vector) test.get("root");
            emergencyPoliceArray = new ArrayList<Map<String, String>>();
            for (int j = 0; j < emergencyVector.size(); j++) {
                Hashtable hm = (Hashtable) emergencyVector.get(j);
                String title = (String) hm.get("title");
                String location = (String) hm.get("location");
                Vector phn = (Vector) hm.get("phone");
                for (int i = 0; i < phn.size(); i++) {
                    Hashtable hphn = (Hashtable) phn.get(i);
                    String phone1 = (String) hphn.get("phn1");
                    String phone2 = (String) hphn.get("phn2");
                    String phone3 = (String) hphn.get("phn3");
                    HashMap<String, String> mp = new HashMap<String, String>();
                    mp.put("Phn", phone1);
                    mp.put("Phone2", phone2);
                    mp.put("Phone3", phone3);
                    mp.put("NameHeading", "Name");
                    mp.put("PhnHeading", "Phn no.");
                    mp.put("LocationHeading", "Location");
                    mp.put("Title", title);
                    mp.put("Name", title);
                    mp.put("Location", location);
                    emergencyPoliceArray.add(mp);
                }
            }
        } catch (IOException ex) {
        }
        showForm("EmergencyListDetails", null);
    }

【问题讨论】:

    标签: java list codenameone renderer


    【解决方案1】:

    如果渲染器条目之间存在差异(例如,一个条目有按钮,而另一个没有),这可能会影响所有列表,而不仅仅是按钮可见的条目。

    当您有互动时,我们强烈建议避免使用列表。对于这样的用例,它充其量是骇人听闻的,并且对于这种常见的情况,与容器相比,它没有提供任何性能优势。

    【讨论】:

      猜你喜欢
      • 2019-11-07
      • 1970-01-01
      • 2015-01-14
      • 1970-01-01
      • 2020-04-27
      • 2014-08-23
      • 1970-01-01
      • 2019-01-24
      • 1970-01-01
      相关资源
      最近更新 更多