1

我正在使用 LWUIT 1.5 选项卡来显示通知。我有三个Tabs,我从 php Web 服务获取通知。我成功获取了 first 的通知列表Tab。但是对于接下来的两个Tabs,我无法理解我应该写什么代码

  1. 检测第二个/第三个Tab被点击。我知道如何添加commandListenerButton. 有什么commandListener可供Tab选择的?
  2. Tab从服务器接收到新数据时如何刷新内容?

    私人无效showNotificationList(){

    try {
    
        Form f = new Form("Notifications");
        f.setScrollable(false);
        f.setLayout(new BorderLayout());
        final List list = new List(getNotifications()); //gets hashtables - notices
        list.setRenderer(new GenericListCellRenderer(createGenericRendererContainer(), createGenericRendererContainer()));
        list.setSmoothScrolling(true);
        //System.out.println("adding list component to listview");
        list.addActionListener(new ActionListener() {
    
            public void actionPerformed(ActionEvent evt) {
                int i = list.getSelectedIndex();
                noticeDetailsForm(notices[i]);
                //Dialog. show( "title",  notices[i].toString(),  "ok",  "exitt");
            }
        });
        //Container c2 = new Container(new BoxLayout(BoxLayout.Y_AXIS));
        //c2.addComponent(list);
        Tabs tabs = new Tabs(Tabs.TOP);
        tabs.addTab("Recent", list);
        tabs.addTab("Urgent", new Label("urgent goes here"));
        tabs.addTab("Favourites", new Label("favs goes here"));
    
        //f.addComponent(tabs);
        f.addComponent(BorderLayout.CENTER, tabs);
        Command backComm = new Command("Back") {
    
            public void actionPerformed(ActionEvent ev) {
                Dashboard.dbInstance.setUpDashboard();
    
            }
        };
        f.addCommand(backComm);
        //System.out.println("showing lsit form");
        f.show();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    

    }

    private Container createGenericRendererContainer() throws IOException { //System.out.println("container called");
    
    //System.out.println("container called");
    Container c = new Container(new BorderLayout());
    c.setUIID("ListRenderer");
    
    Label xname = new Label("");
    Label description = new Label();
    Label focus = new Label("");
    Container cnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    xname.setName("Name");
    xname.getStyle().setBgTransparency(0);
    xname.getStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM));
    //description.setFocusable(true);
    description.setName("Description");
    cnt.addComponent(xname);
    cnt.addComponent(description);
    c.addComponent(BorderLayout.CENTER, cnt);
    Button thumb = new Button(Image.createImage("/res/home-work.png"));
    //Image img = Image.createImage("/res/home-work.png");
    c.addComponent(BorderLayout.WEST, thumb);
    
    return c;
    

    }

    private Hashtable[] getNotifications() { int total = notices.length; //System.out.println(total); 哈希表 [] 数据 = 新哈希表 [总计]; //Hashtable[] data = new Hashtable[5]; /数据[0] = 新哈希表();data[0].put("姓名", "Shai"); data[0].put("姓氏", "Almog"); data[0].put("选中", Boolean.TRUE); /

    for (int i = 0; i < total; i++) {
        data[i] = new Hashtable();
        //System.out.println(notices[i].getName());
        data[i].put("Name", notices[i].getName());
        data[i].put("Description", notices[i].getDescription());
        data[i].put("Id", Integer.toString(notices[i].getId()));
    }
    
    return data;
    

    }

4

1 回答 1

2

1)我遇到了同样的问题,我通过覆盖not the来解决它Keyreleased, 并且在其中我检查关注的组件,如果它是get "tab.selectedIndex" 来检测我所在的位置并加载适当的数据。这是示例代码(这在我扩展 Form 的派生表单中)FormTabTabTab

**

public void keyReleased(int keyCode) {
        Component p=this.getFocused();
       String str= p.getClass().getName();
    if(str.toLowerCase().indexOf("radiobutton")!=-1){    // Radiobutton because when u 
  Here do tab specific work                              focus on the 
                                                         tab it returns radiobutton.                                    
                                                         lwuit understands tabs as list   
                                                         of radiobuttons 
                      }**

2)关于刷新数据我做了一个解决方案,但我不知道它是否正确我得到新数据,创建新数据List并删除旧数据并附加新数据然后调用Form.repaint()

于 2012-03-11T11:02:57.913 回答