2012-03-08 18 views
1

我使用LWUIT 1.5標籤顯示通知。我有三個Tabs,我從php web服務中獲取通知。我成功提取了第一個Tab的通知列表。但是對於接下來的兩個Tabs,我不理解,我應該寫什麼代碼LWUIT 1.5如何捕獲標籤的點擊事件,獲取來自服務器的內容,它顯示選中的標籤?

  1. 檢測第二/第三Tab被點擊。我知道如何將commandListener添加到Button。什麼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; 
    

    }

    私人哈希表[] getNotifications(){ INT總= notices.length; //System.out.println(total); Hashtable [] data = new Hashtable [total]; // Hashtable [] data = new Hashtable [5]; /數據[0] =新的Hashtable(); data [0] .put(「Name」,「Shai」); data [0] .put(「Surname」,「Almog」); data [0] .put(「Selected」,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; 
    

    }

回答

2

1)I有同樣的問題,我解決它通過重寫Form不是TabKeyreleased和裏面我檢查該聚焦在組分和如果是Tab GET「tab.selectedIndex」,以檢測其Tab我並加載相應的數據。 下面是示例代碼(這個擴展的形式我的派生形式內)

**

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();