Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete objects in GridLayout before adding new objects

Tags:

android

Every time i press a button i fill a GridLayout with several buttons. This is the code that do it, but i don't think it's necessary for you to understand my problem

for(int i=0; i < numeroBottoni;i++){
        Spec row = GridLayout.spec(numeroRiga, 1); 
        Spec colspan = GridLayout.spec(numeroColonna, 1);
        GridLayout.LayoutParams gridLayoutParam = new GridLayout.LayoutParams(row,colspan);
        gridLayoutParam.width=larghezzaColonna;
        gridLayoutParam.height=larghezzaColonna;// l'altezza della colonna la faccio uguale alla larghezza
        gridLayout.addView(buttonName,gridLayoutParam);

}

The new buttons overlap the old ones, so i suppose i should "delete" the old buttons before adding the new ones. But i dont know what i should do. I don't know if i have to "delete" the button or if i have to "clean" the GridLayout.

I tried to call invalidate() both on button and GridLayout but this is not the solution

like image 605
MDP Avatar asked Dec 12 '25 13:12

MDP


1 Answers

Try this code

gridLayout.removeAllViews();

before adding the new views. Before your for loop in your code

like image 77
Pragnani Avatar answered Dec 15 '25 05:12

Pragnani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!