1

LWUIT 1.5 タブを使用して通知を表示しています。私は 3 つ持っておりTabs、php Web サービスから通知を取得しています。最初の通知のリストを正常に取得しましたTab。しかし、次の 2 つTabsについては、どのコードに書き込むべきか理解できていません。

  1. 2 番目/3 番目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;
    

    }

    private Hashtable[] getNotifications() { int total = notifications.length; //System.out.println(合計); Hashtable[] data = new Hashtable[total]; //Hashtable[] data = new Hashtable[5]; / data[0] = new Hashtable(); data[0].put("名前", "シャイ"); 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をオーバーライドすることで解決しましたKeyreleased.FormそのTab 中でフォーカスされているコンポーネントをチェックし、Tabget "tab.selectedIndex"であるかどうかを検出してTab適切なデータをロードします. これがサンプルコードです(これは Form を拡張する私の派生フォーム内にあります)

**

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 に答える