Android (Interface Programming # 4-radiobutton)

Source: Internet
Author: User
In Android, radiobutton is similar to radiobutton in other languages.
In Android, radiobutton is the same as other interface elements inherited from view. It can be used independently. onclicklistener is the most commonly used method, to use the radiogroup class, this class is also a layout class (layout). You can use the layoutparams object to place the relative location of radiobutton.
1. Use radiosbutton separately
This can be used in the activity class.
Radiobutton rbtn = new radiobutton (this );
Rbtn. setonclicklistener (New onclicklistener () {public void onclick (view v) {settitle ("test! ")}});
Ii. Combined Use
Public class test extends activity implements oncheckedchangelistener
{
Private radiogroup mgroup = NULL;
@ Override public void oncreate (bundle icicle)
{
Super. oncreate (icicle );
Mgroup = new radiogroup (this );
Mgroup. setorientation (radiogroup. Vertical );
Mgroup. setoncheckedchangelistener (this );
Radiobutton btn1 = new radiobutton (this );
Btn1.setid (100 );
Mgroup. addview (btn1 );
Radiobutton btn2 = new radiobutton (this );
Btn2.setid (101 );
Mgroup. addview (btn2 );
Mgroup. setoncheckedchangelistener (this );
}
Public void oncheckedchanged (radiogroup arg0, int arg1)
{
Switch (arg0.getcheckedradiobuttonid ())
{
Case 100:
Settitle ("You cliecked radiobutton 1"); break;
Case 101:
Settitle ("You cliecked radiobutton 2"); break;
Default:
Break;

}
}
}

Related Article

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.