Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
This is Om Parkash Kaushik making a query in regards to List sorting in java2me as Contacts render-er I am tagging the code with this query and please reply that how i can sort the list with the use of LWUIT api.
The code is follow as
Java
public class ContactsRenderer extends Container implements ListCellRenderer {

//private Label upperText = new Label("");///////for Device ID
private Label SwitchID = new Label("");
private Label lowerText = new Label("");
private Label deviceID = new Label("");
private Label pic = new Label(""); //////for main Picture
private Label pic2 = new Label("");
private Label pic3 = new Label("");
//private Label Rmk = new Label("");//////for remarks
private Label focus = new Label("");
//private Label SwitchName = new Label("");
private TextArea txtDev = new TextArea();
public ContactsRenderer() {
setLayout(new BorderLayout());
pic.setPreferredSize(new Dimension(43,63));
//pic2.setPreferredSize(new Dimension(26,26));
//pic3.setPreferredSize(new Dimension(28,26));
pic.setAlignment(Label.LEFT);
pic.getStyle().setBgTransparency(0);
pic2.getStyle().setBgTransparency(0);
pic3.getStyle().setBgTransparency(0);
addComponent(BorderLayout.WEST, pic);
TableLayout tblLayout = new TableLayout(2,2);
Container Chcnt = new Container(tblLayout);
Container cnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
lowerText.getStyle().setBgTransparency(0);
lowerText.getStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE));
lowerText.setAlignment(Label.LEFT);
txtDev.getStyle().setBgTransparency(0);
txtDev.getStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL));
txtDev.getStyle().setBorder(Border.createEmpty());
txtDev.setAlignment(TextArea.LEFT);
 //////this is for the table layout for the constraint on main screen
TableLayout.Constraint tblCnt = tblLayout.createConstraint();
tblCnt.setWidthPercentage(85);
Chcnt.addComponent(tblCnt,txtDev);
//tblCnt = tblLayout.createConstraint();
//tblCnt.setWidthPercentage(20);
Chcnt.addComponent(pic3);
tblCnt = tblLayout.createConstraint();
tblCnt.setWidthPercentage(85);
//tblCnt.setHeightPercentage(20);
Chcnt.addComponent(tblCnt,lowerText);
tblCnt = tblLayout.createConstraint();
tblCnt.setWidthPercentage(15);
Chcnt.addComponent(tblCnt,pic2);
cnt.addComponent(Chcnt);
addComponent(BorderLayout.CENTER, cnt);
focus.getStyle().setBgTransparency(100);
}

public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected) {
 if(!( value instanceof ListItem))
                throw new IllegalArgumentException("Value is not instance of ListItem");
 
            ListItem item = (ListItem)value;
            if (item.GetSwName()==null){
            	txtDev.setText(item.getText());
            }
            else{            	
            	txtDev.setText(item.getText());
            	String Msg = txtDev.getText();
            	Msg = Msg + " | " + item.GetSwName();
            	txtDev.setText(Msg);
            }
            if (item.getText2().equalsIgnoreCase("0N")){
            	lowerText.getStyle().setFgColor(0x308014);
            }else{
            	lowerText.getStyle().setFgColor(0x000000);
            }  
           
           //Rmk.setText(item.getPrc());
           //txtDev.setText(item.getText());
SwitchID.setText(item.getswID());
lowerText.setText(item.getText2());
deviceID.setText(item.getText3());
pic.setIcon(item.getImg());
pic2.setIcon(item.getImg2());
pic2.getStyle().setBgTransparency(0);
pic3.setIcon(item.getImg3());
pic3.getStyle().setBgTransparency(0);
getStyle().setBorder(Border.createBevelRaised());
return this;
}

public Component getListFocusComponent(List list) {
return focus;
}
}

thanks n regards
Om Parkash Kaushik
Posted
Updated 12-Jan-12 20:47pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900