简体   繁体   English

如何使用lwuit在列表中显示文本,图像,星级

[英]how to show text,image,rating stars in list using lwuit

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. 在Lwuit列表中,我将图像设置在右侧字段中,在左侧,我想在框布局中显示两个标签和评级星。 I am using list that extend container. 我正在使用扩展容器的列表。 I set the container layout as boxlayout.x_axis. 我将容器布局设置为boxlayout.x_axis。 I am adding one container within the container and show 5 rating stars in it. 我要在容器中添加一个容器,并在其中显示5个星级。 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. 我已添加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;
        }
    }

A list doesn't support interaction in this way. 列表不支持这种方式的交互。 You should use Container and component hierarchy. 您应该使用容器和组件层次结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM