0

在 Lwuit 列表中,我在右侧字段中设置图像,在左侧我想在框布局中显示两个标签和评级星。我正在使用扩展容器的列表。我将容器布局设置为 boxlayout.x_axis。我在容器中添加一个容器并在其中显示 5 颗评级星。在运行时,我想根据运行时输入更改评级星图像,所以请指导我这样做。我加了 5 颗星,但在运行时没有改变。

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

1 回答 1

0

列表不支持这种方式的交互。您应该使用容器和组件层次结构。

于 2013-06-13T12:05:37.357 回答