1

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

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

列表的渲染器是 public class MyRenderer extends TextArea implements 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;}


 }

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

4

1 回答 1

2

你有可能使用 aSelectionListener而不是 aActionListener吗?

于 2012-06-30T09:07:26.130 回答