Android Radio box Problem-radiobutton State disorder (RadioButton check not work)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.