LWUIT列表不滚动

时间:2012-06-29 18:09:25

标签: list java-me lwuit

我在使用LWUIT设计的j2ME项目中插入了一个列表。代码如下

  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;}


 }

问题是当在设备上,我尝试滚动列表时,立即选择我触摸的项目并打开它的新表单。我根本无法滚动列表。请帮我解决这个问题。

1 个答案:

答案 0 :(得分:2)

您是否可以使用SelectionListener代替ActionListener