List with checkbox using LWUIT

后端 未结 1 1465
离开以前
离开以前 2021-01-15 19:25

I am using LWUIT for getting a search facility for selection in the List. Now I want to know how can I display the list with CheckBoxes?

         


        
相关标签:
1条回答
  • 2021-01-15 20:16

    I don't know if there is a more simple solution then mine, but mine is highly customizable and can serve for a lot of purposes.

    List l = new List;
    
    Vector v = new Vector();
    for(int i = 0; i < 10; ++i){
       v.addElement(new CheckItem("itemtekst"));
    }
    
    l.setListCellRenderer(new CheckItemRenderer());
    l.setModel(new CheckItemModel(v));
    

    the code above makes it work. As you can guess you have to make a new class and override two to make it work.

    CHECKITEM: this class has a string and an image. as well as setters and getters. it also has a boolean that shows if it is checked or not.

    CHECKITEMRENDERER: has a label for the string and the image of the checkitem it extends Container and implements ListCellRenderer

    CHECKITEMMODEL: this extends the defaultlistmodel. it has methods to get the checkeditems and setthem checked or unchecked.

    to recap:

    • set the correct items in the vector
    • set the correct renderer
    • set the correct model

    and to use it add an actionlistener or it will al be for nothing.

    0 讨论(0)
提交回复
热议问题