2012-06-29 78 views
1

我在我的j2ME項目中插入了一個使用LWUIT設計的列表。代碼如下所示LWUIT List not scrolling

Button btnHome; 
    Button btnExit; 
    List list; 
    setScrollableY(false); 
    setScrollable(false); 

    list = new List(); 
    MyRenderer render = new MyRenderer(); 
    list.setListCellRenderer(render);   

     list.getStyle().setFgColor(0xfaedf2); 
     list.setSmoothScrolling(true);  
     list.addSelectionListener(new SelectionListener(){ 
      public void selectionChanged(int i, int i1) { 
      try { 
      InformationForm form = new InformationForm();           
      form.show(); 
      } catch (IOException ex) { 
       ex.printStackTrace(); 
      } 


     } 


     }); 

     String[] arrString = builder.getArrName(); 
     System.out.println(arrString.length); 
     for (int i = 0; i < arrString.length ; i++) 
       { 
       list.addItem(arrString[i]); 
      // System.out.println("item no " + i +" = " +arrString[i] + "added in list"); 
       }   

      BorderLayout bl=new BorderLayout(); 


setLayout(bl); 
Container holdingContainer=new Container(new FlowLayout(Component.LEFT)); 
Container c0 = new Container(new BoxLayout(BoxLayout.X_AXIS)); 
Container c1 = new Container(new FlowLayout(Component.LEFT)); 
Container c2 = new Container(new FlowLayout(Component.LEFT)); 

Container footerContainer=new Container(new BoxLayout(BoxLayout.X_AXIS)); 

c0.addComponent(cityChoice); 
c0.addComponent(btnFilter); 


    //c2.addComponent(list); 

    c1.setPreferredH(25); 
    holdingContainer.addComponent(c0); 
    holdingContainer.addComponent(c1); 
    getStyle().setBgColor(0x730E36); 
// holdingContainer.addComponent(c2); 
    holdingContainer.setPreferredH(280); 
    holdingContainer.setScrollableY(true); 

    addComponent(BorderLayout.CENTER,list); 
    //addComponent(BorderLayout.WEST,holdingContainer); 
    footerContainer.getStyle().setMargin(Component.LEFT, 0); 
    footerContainer.addComponent(btnHome); 
    footerContainer.addComponent(btnExit); 

    addComponent(BorderLayout.SOUTH,footerContainer); 

對列表中的渲染器, 公共類MyRenderer擴展的TextArea實現ListCellRenderer {

public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected){ 
getStyle().setBorder(Border.createEmpty()); 
getStyle().setFgColor(0xfaedf2); 
getStyle().setBgColor(isSelected ? 0x630A2E : 0x730E36); 

setText(value.toString()); 

if (isSelected) { 
setFocus(true); 
getStyle().setBgTransparency(100); 
} else { 
setFocus(false); 
getStyle().setBgTransparency(0); 
} 
return this; 
} 
public Component getListFocusComponent(List list){ 
    return null;} 


} 

問題是,當在設備上,我嘗試滾動列表,該項目我立即選擇了它,並打開它的新窗體。我根本無法滾動列表。請幫我解決這個問題。

回答

2

是否有可能您使用的是SelectionListener而不是ActionListener

+0

是的,這是問題,我將它改爲動作監聽器,現在它工作正常。 – Dania