3

I have created a small "widget" in my project by extending a ViewGroup. In that widget I want to add and remove buttons (ImageView's).

It was easy to create the widget and adding buttons worked fine but sometimes when I want to remove a button I added earlier it's still displayed on the screen even though the code has been accessed.

The widget is added through the layout xml and I add/removes buttons by calling on a function in the widget from my activity. To be more precise; my widget gets an onClickEvent and sends it to my activity who tells my widget to remove the button through removeView().

I have tried with invalidate() on both the widget and the button. I have also tried to set it to invisible, layout(0,0,0,0) and a few more but nothing is working. Anyone who got an idea what I'm doing wrong?

Edit: Answer in comment below

t791
  • 31
  • 1
  • 3
  • 1) Is the button still interactive after supposedly being removed? 2) Did you try to call `forceLayout` on the `ViewGroup` after removing the button? – Xion Apr 20 '11 at 08:26
  • 1) No I remove the onClickListener before I remove it (on that specific button). 2) Tried it now and it didn't work. – t791 Apr 20 '11 at 08:37
  • 4
    Found the error my self and it was me who did something stupid. I actually added the button I wanted to remove several times so when I finally tried to remove it I only had reference to the last added button. I've been working on this error for several days =/. Guess it helped to write it as a question.. Anyway, hope this could help someone else as stupid as me. – t791 Apr 20 '11 at 08:50
  • (Couldn't add this as an answer since I'm a new member) – t791 Apr 20 '11 at 08:50

0 Answers0