0

In Lwuit list, I set the image in right field and in left side I want to show two labels and rating stars in box layout. I am using list that extend container. I set the container layout as boxlayout.x_axis. I am adding one container within the container and show 5 rating stars in it. At run time I want to change rating star image depending on the run time input so pls guide me to do this. I have added 5 stars but it is not changed at run time.

class WidgetRenderer extends Container implements ListCellRenderer {
        private Image[] images;
        private Button orgImgButton;
        private Image orgImg, starFocusImg, starUnfocusImg;
        private Container contImage, contDet, contStar, contOrg;
        private TextField orgNameLabel, locationLabel, ratingLabel;
        private Button starButton;

        public WidgetRenderer() {
            super();
            try {
                setLayout(new BoxLayout(BoxLayout.X_AXIS));
                contDet = new Container(new BoxLayout(BoxLayout.Y_AXIS));
                contOrg = new Container(new BoxLayout(BoxLayout.Y_AXIS));
                contImage = new Container();
                contStar = new Container(new BoxLayout(BoxLayout.X_AXIS));
                starFocusImg = Image.createImage("/images/star.jpg");
                starUnfocusImg = Image.createImage("/images/star1.jpg");

                orgNameLabel = new TextField(8);
                orgNameLabel.setGrowByContent(true);
                orgNameLabel.setEditable(false);
                locationLabel = new TextField(8);
                locationLabel.setGrowByContent(true);
                locationLabel.setEditable(false);

                orgNameLabel.setUnselectedStyle(DefaultLayout.OrgListStyle());
                orgNameLabel.setSelectedStyle(DefaultLayout.OrgListStyle());
                orgNameLabel.setPressedStyle(DefaultLayout.OrgListStyle());
                locationLabel.setSelectedStyle(DefaultLayout
                        .locationListStyle());
                locationLabel
                        .setPressedStyle(DefaultLayout.locationListStyle());
                locationLabel.setUnselectedStyle(DefaultLayout
                        .locationListStyle());

                contOrg.addComponent(orgNameLabel);
                contOrg.addComponent(locationLabel);
                contDet.addComponent(contOrg);
                int totalCount = 5;

                for (int i = 0; i < totalCount; i++) {
                    starButton = new Button(DefaultLayout.CreateScaledImage(
                            starFocusImg,
                            DefaultLayout.screenWidth() * 6 / 100,
                            DefaultLayout.screenHeight() * 6 / 100));
                    starButton
                            .setSelectedStyle(DefaultLayout.starButtonStyle());
                    starButton.setUnselectedStyle(DefaultLayout
                            .starButtonStyle());
                    starButton.setPressedStyle(DefaultLayout.starButtonStyle());
                    contStar.addComponent(starButton);
                }

                contDet.addComponent(contStar);
                // addComponent(contImage);
                addComponent(contDet);
            } catch (Exception ex) {
                System.out.println("ex" + ex.getMessage());
            }
        }

        public Component getListCellRendererComponent(List list, Object value,
                int index, boolean isSelected) {
            try {
                setFocus(isSelected);
                for (int i = 0; i < list.size(); i++) {
                    if (index == i) {
                        orgNameLabel.setText(tempName[i]);
                        locationLabel.setText(districtDesc[i] + ","
                                + townDesc[i]);
                        // orgImgButton.setIcon(loadImage(thumbnailURL));
                        int ratingCount = Integer.parseInt(totalRatingCount[i]);
                        int totalCount =5;
                        if(ratingCount <= totalCount)
                        {
                            //dont know how to do change in image
                        }
                        if (isSelected) {
                            getStyle().setBgColor(0x00BFFF);
                            getStyle().setBgTransparency(100);

                        } else
                            getStyle().setBgTransparency(0);
                    }
                }
            } catch (Exception e) {

            }
            return this;
        }

        public Component getListFocusComponent(List arg0) {
            return null;
        }
    }
Kara
  • 6,115
  • 16
  • 50
  • 57
seipl
  • 11
  • 3

1 Answers1

0

A list doesn't support interaction in this way. You should use Container and component hierarchy.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65