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.
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);
}