2012-03-08 5 views
1

通知を表示するのにLWUIT 1.5タブを使用しています。私は3つのTabsがあり、私はPHPのWebサービスから通知を取得します。最初にTabの通知リストを正常に取得しました。しかし、2次Tabsのために私はその第二/第三Tabがクリックされた検出LWUIT 1.5タブクリックイベントをキャプチャし、サーバーからコンテンツを取り出し、選択したタブに表示する方法は?

  1. に書き込む必要がありますどのようなコードを理解するために失敗しています。 ButtoncommandListenerを追加する方法を知っています。 Tabを選択すると、commandListenerはありますか?
  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 []データ=新しいHashtable [合計]。 // Hashtable [] data =新しいHashtable [5]; /data [0] = new Hashtable(); データ[0] .put( "Name"、 "Shai"); データ[0] .put( "姓"、 "Almog"); データ[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)私は同じ問題を抱えていたと私は集光されるコンポーネントのチェックFormないTab 及びその内部のKeyreleasedをオーバーライドし、それを解決しそれがTabの場合、「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()と呼んでください。

関連する問題