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;
}
}
}