I am using LWUIT 1.5 tabs to show notifications. I have three Tabs
and I fetch notifications from a php web service. I successfully fetched list of notifications for first Tab
. But for next two Tabs
I am failing to understand what code I should write to
- Detect that second/third
Tab
is clicked. I know how to addcommandListener
to aButton
. WhatcommandListener
is there forTab
selection? How to refresh content of a
Tab
when new data is received from the server?private void 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[total]; //Hashtable[] data = new Hashtable[5]; /data[0] = new 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;
}
1)I had the same problem and I solved it by overriding
Keyreleased
of theForm
not theTab
and inside it I check for the component that is focused and if it is theTab
get "tab.selectedIndex" to detect in whichTab
I am and load appropriate data . Here is Sample code(this inside the my derived form that extends Form )**
2)and about refreshing the data I did a solution and I don't Know if its right I get the new data , create new
List
and remove the old one and attach the new one then callForm.repaint()
;