Recent projects need to dynamically create a single-selection marquee.
The general idea is:
1. Dynamically create a radiogroup.
2. Create the RadioButton dynamically and add it to the Radiogroup.
If you inherit RadioButton, and radiogroup to achieve a variety of other words, accidentally will encounter a variety of diseases.
(Ah ah ah, radiogroup I will give you a lot of small monkeys).
The most common is the state disorder of RadioButton:
(1) A RadioButton is not selected, usually the first one.
(2) Even several RadioButton can be selected.
The workaround is to:
1. Dynamically add RadioButton must set a unique ID for each radiobutton
2. If you must use Api:radiobuttonsetChecked
Try to set the default selection after Radiogroup add RadioButton is finished. is to try to call the Radiogroup after it has been added.
setChecked()这个接口。
3. If all of the above are resolved, there is a button selected. Well, congratulations. Remember to find a suitable place for Radiogroup to call Clearcheck () this interface.
(I met the first one, the code put this radiogroup and radiobutton into the Expandablelistview, I guess the reason is because of object reuse caused, and finally had to pick a place
Plug in the Clearcheck () function and reset the state to solve the problem. )
Android Radio box Problem-radiobutton State disorder (RadioButton check not work)