Images about buttons are not updated

12 views
Skip to first unread message

rdvg...@gmail.com

unread,
Dec 4, 2018, 9:11:55 AM12/4/18
to CodenameOne Discussions
Hi,

Inside my app create a section to show non-invasive ads. The addresses of these ads are in a database and every time you enter this section the database is read again. Change the addresses of the images in the Database but the images do not refresh on the buttons.

My Code:
    private void formaOfertas(Container cnOfertas, ArrayList aAnuncios) {

        cnOfertas.removeAll();
        cnOfertas.setScrollableY(true);
        Container cntB = new Container();
        int size = Display.getInstance().convertToPixels(15);
        int ancho = Display.getInstance().getDisplayWidth();
        ancho = (int) (ancho - (ancho * 0.03d));
        boolean ciclo = true;
        int c = 2;
        while (ciclo) {
            c++;
            size = (int) (ancho / c);
            int r = ancho % c;
            if (r <= 0 || c >= aAnuncios.size()) {
                ciclo = false;
            }
        }

        Button bt[];
        bt = new Button[aAnuncios.size()];
        for (int i = 0; i < aAnuncios.size(); i++) {
            Campana1 cM1 = (Campana1) aAnuncios.get(i);
            bt[i] = new Button();
            bt[i].setUIID("Label");
            Image img;
            if (cM1.getRutaLogo().equals("") || cM1.getRutaLogo().equals("null")) {
                img = res.getImage("promo.png").scaled(size, size);
            } else {
                EncodedImage lugar = EncodedImage.createFromImage(Image.createImage(size, size, 0xffcccccc), true);
                img = URLImage.createToStorage(lugar, Integer.toString(cM1.getCampana()), cM1.getRutaLogo());
            }
            bt[i].setIcon(img);
            cntB.addComponent(bt[i]);

            bt[i].addActionListener((e) -> {
                Display.getInstance().execute(cM1.getEnlace());
            });
        }
        Container cnCentro = new Container(new BoxLayout(BoxLayout.Y_AXIS)).add(cntB);
        cnOfertas.add(BorderLayout.CENTER, cnCentro);
    }

rdvg...@gmail.com

unread,
Dec 4, 2018, 9:43:30 PM12/4/18
to CodenameOne Discussions
Hi,
In my app, as many buttons are created as campaign records. The images of the buttons change depending on who creates or modifies the campaign on a web page created by me. Each time a URL is changed you must change the image of each button.
Attached image of my app executed from the simulator, with the initial images (which were not updated).

CodenameOne Screenshot 39.png


As proof, download the app from my cell phone and I loaded it again, to my surprise the images were renewed. However, I changed the URL again but the images do not change on the buttons.

I include an image of the cell phone with the problem I mentioned.


Screenshot_20181204-213156.jpg




rdvg...@gmail.com

unread,
Dec 4, 2018, 10:03:50 PM12/4/18
to CodenameOne Discussions
Ups, I corrected the problem.

Shai Almog

unread,
Dec 5, 2018, 12:49:50 AM12/5/18
to CodenameOne Discussions
Hi,
URLImage caches images locally. You need to change the storage file name too in order for the image to be fetched again, alternatively you can delete the storage file.

rdvg...@gmail.com

unread,
Dec 5, 2018, 6:55:39 AM12/5/18
to CodenameOne Discussions
Thanks
Reply all
Reply to author
Forward
0 new messages