Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove dynamicallly created radiobuttons from a radiogroup in Android

:) My RadioGroup's RadioButtons get dynamically created from an ArrayList (which resides in my main activity) full of links like so:

ArrayList = { "hxxp://helloworld.com", "hxxp://helloworld2.net", ..., "hxxp://whatever.com" }

then I have a new class called "links" that gets called from a menu button in my main activity which sets a nice layout with a radiobubtton per link (in a scrollview) and a "go!" button on the bottom of the page (relative layout).

This all works great except for one thing. If you exit the application using the back button, and go back into the application by clicking on the icon in the Android menu, you get to the main activity, then click the "links" button in the menu and they are doubled each time. ??? like so:

link 0
link 1
link 2
link 0 (again)
link 1 (again)
link 2 (again)

This appends the links to the bottom each time you come back to the "links" activity from leaving. Is there some way I can call a method to clear all radio buttons generated form the last session in the links activity before putting them into the RadioGroup? I tried changing my onPause() to finish(); I tried freeing the cache with RadioGroup.destroyDrawingCache(); nothing seems to do it.

like image 458
jeremy Avatar asked Nov 27 '10 21:11

jeremy


1 Answers

You can remove your radio buttons which were dynamically created using like this:

RadioGroup rg=(RadioGroup)findViewById(R.id.radioGroupnew1);
rg.clearCheck();
rg.removeAllViews();
like image 131
GOBINATH.M Avatar answered Oct 17 '22 15:10

GOBINATH.M